MCPcopy
hub / github.com/tanelpoder/0xtools / test_query_execution

Function test_query_execution

xtop/tests/test_tui_query.py:13–74  ·  view source on GitHub ↗

Test query execution with debug logging

()

Source from the content-addressed store, hash-verified

11from core import XCaptureDataSource, QueryEngine, QueryParams
12
13def test_query_execution():
14 """Test query execution with debug logging"""
15
16 # Setup logging
17 import logging
18 logging.basicConfig(
19 level=logging.DEBUG,
20 format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
21 )
22
23 logger = logging.getLogger('test')
24
25 try:
26 # Initialize components
27 logger.info("Initializing data source...")
28 data_source = XCaptureDataSource('./out')
29
30 logger.info("Initializing query engine...")
31 query_engine = QueryEngine(data_source)
32
33 # Get available time range
34 logger.info("Getting available time range...")
35 data_min, data_max = data_source.get_time_range()
36 logger.info(f"Data time range: {data_min} to {data_max}")
37
38 # Create query params
39 params = QueryParams(
40 query_type='top',
41 where_clause='1=1',
42 group_cols=['STATE', 'USERNAME', 'EXE', 'COMM', 'SYSCALL', 'FILENAME', 'EXTRA_INFO'],
43 low_time=data_min,
44 high_time=data_max,
45 limit=10
46 )
47
48 logger.info(f"Executing query: {params.query_type}")
49
50 # Execute query with debug enabled
51 result = query_engine.execute_with_params(params, debug=True)
52
53 logger.info(f"Query returned {result.row_count} rows")
54 logger.info(f"Columns: {result.columns}")
55 logger.info(f"Execution time: {result.execution_time:.3f}s")
56
57 if result.row_count > 0:
58 logger.info("First row:")
59 for col, val in result.data[0].items():
60 logger.info(f" {col}: {val}")
61 else:
62 logger.warning("No data returned!")
63
64 # Check available CSV files
65 logger.info("\nChecking available CSV files:")
66 for pattern in ['xcapture_samples_*.csv', 'xcapture_syscend_*.csv',
67 'xcapture_iorqend_*.csv', 'xcapture_kstacks_*.csv']:
68 files = list(data_source.datadir.glob(pattern))
69 logger.info(f" {pattern}: {len(files)} files")
70 if files:

Callers 1

test_tui_query.pyFile · 0.85

Calls 6

get_time_rangeMethod · 0.95
execute_with_paramsMethod · 0.95
XCaptureDataSourceClass · 0.90
QueryEngineClass · 0.90
QueryParamsClass · 0.90
errorMethod · 0.80

Tested by

no test coverage detected