Skip to content

Commit b40c605

Browse files
committed
test/case: simplify and add load-bearing sleep(2)
This (new) test sometimes fail on HW, so let's hold off a while before sending our log messages. Ths should allow the DUTs to settle. Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 1bbd80d commit b40c605

File tree

2 files changed

+91
-72
lines changed

2 files changed

+91
-72
lines changed

test/case/syslog/advanced_compare/test.py

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
import infamy
1111
import time
1212

13+
TEST_MESSAGES = [
14+
("daemon.emerg", "Emergency: system is unusable"),
15+
("daemon.alert", "Alert: immediate action required"),
16+
("daemon.crit", "Critical: critical condition"),
17+
("daemon.err", "Error: error condition"),
18+
("daemon.warning", "Warning: warning condition"),
19+
("daemon.notice", "Notice: normal but significant"),
20+
("daemon.info", "Info: informational message"),
21+
("daemon.debug", "Debug: debug-level message"),
22+
]
23+
1324
with infamy.Test() as test:
1425
with test.step("Set up topology and attach to target DUT"):
1526
env = infamy.Env()
@@ -62,51 +73,53 @@
6273
}
6374
})
6475

76+
time.sleep(2)
77+
6578
with test.step("Send test messages at all severity levels"):
66-
tgtssh.runsh("logger -t advtest -p daemon.emerg 'Emergency: system is unusable'")
67-
tgtssh.runsh("logger -t advtest -p daemon.alert 'Alert: immediate action required'")
68-
tgtssh.runsh("logger -t advtest -p daemon.crit 'Critical: critical condition'")
69-
tgtssh.runsh("logger -t advtest -p daemon.err 'Error: error condition'")
70-
tgtssh.runsh("logger -t advtest -p daemon.warning 'Warning: warning condition'")
71-
tgtssh.runsh("logger -t advtest -p daemon.notice 'Notice: normal but significant'")
72-
tgtssh.runsh("logger -t advtest -p daemon.info 'Info: informational message'")
73-
tgtssh.runsh("logger -t advtest -p daemon.debug 'Debug: debug-level message'")
74-
time.sleep(1)
79+
for priority, message in TEST_MESSAGES:
80+
tgtssh.runsh(f"logger -t advtest -p {priority} '{message}'")
81+
time.sleep(2)
7582

7683
with test.step("Verify exact-errors log contains only error messages"):
77-
rc = tgtssh.runsh("grep -c 'advtest' /var/log/exact-errors 2>/dev/null")
78-
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
79-
if count != 1:
80-
test.fail(f"Expected 1 message in /var/log/exact-errors (error only), got {count}")
84+
rc = tgtssh.runsh("cat /var/log/exact-errors 2>/dev/null")
85+
log_content = rc.stdout if rc.returncode == 0 else ""
8186

82-
rc = tgtssh.runsh("grep -q 'Error: error condition' /var/log/exact-errors 2>/dev/null")
83-
if rc.returncode != 0:
84-
test.fail("Expected error message in /var/log/exact-errors")
87+
# Should contain only the error message
88+
error_messages = [msg for prio, msg in TEST_MESSAGES if "err" in prio]
89+
missing = [msg for msg in error_messages if msg not in log_content]
90+
if missing:
91+
test.fail(f"Missing error messages in /var/log/exact-errors: {missing}")
8592

86-
rc = tgtssh.runsh("grep -c 'Emergency\\|Alert\\|Critical' /var/log/exact-errors 2>/dev/null")
87-
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
88-
if count != 0:
89-
test.fail(f"Expected 0 higher severity messages in /var/log/exact-errors, got {count}")
93+
# Should NOT contain higher severity (emerg, alert, crit) or lower
94+
unwanted_messages = [msg for prio, msg in TEST_MESSAGES if "err" not in prio]
95+
found = [msg for msg in unwanted_messages if msg in log_content]
96+
if found:
97+
test.fail(f"Found unwanted messages in /var/log/exact-errors: {found}")
9098

9199
with test.step("Verify no-debug log blocks all messages"):
92-
rc = tgtssh.runsh("grep -c 'advtest' /var/log/no-debug 2>/dev/null")
93-
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
94-
if count != 0:
95-
test.fail(f"Expected 0 messages in /var/log/no-debug (all blocked), got {count}")
100+
rc = tgtssh.runsh("cat /var/log/no-debug 2>/dev/null")
101+
log_content = rc.stdout if rc.returncode == 0 else ""
102+
103+
# Should be empty (all messages blocked)
104+
all_messages = [msg for _, msg in TEST_MESSAGES]
105+
found = [msg for msg in all_messages if msg in log_content]
106+
if found:
107+
test.fail(f"Expected empty log, found messages in /var/log/no-debug: {found}")
96108

97109
with test.step("Verify baseline log contains info and higher"):
98-
rc = tgtssh.runsh("grep -c 'advtest' /var/log/baseline 2>/dev/null")
99-
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
100-
if count != 7:
101-
test.fail(f"Expected 7 messages in /var/log/baseline (info and higher), got {count}")
102-
103-
rc = tgtssh.runsh("grep -c 'Debug: debug-level' /var/log/baseline 2>/dev/null")
104-
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
105-
if count != 0:
106-
test.fail(f"Expected 0 debug messages in /var/log/baseline, got {count}")
107-
108-
rc = tgtssh.runsh("grep -q 'Info: informational' /var/log/baseline 2>/dev/null")
109-
if rc.returncode != 0:
110-
test.fail("Expected info message in /var/log/baseline")
110+
rc = tgtssh.runsh("cat /var/log/baseline 2>/dev/null")
111+
log_content = rc.stdout if rc.returncode == 0 else ""
112+
113+
# Should contain info and higher (all except debug)
114+
expected_messages = [msg for prio, msg in TEST_MESSAGES if "debug" not in prio]
115+
missing = [msg for msg in expected_messages if msg not in log_content]
116+
if missing:
117+
test.fail(f"Missing messages in /var/log/baseline: {missing}")
118+
119+
# Should NOT contain debug
120+
debug_messages = [msg for prio, msg in TEST_MESSAGES if "debug" in prio]
121+
found = [msg for msg in debug_messages if msg in log_content]
122+
if found:
123+
test.fail(f"Found debug messages in /var/log/baseline: {found}")
111124

112125
test.succeed()

test/case/syslog/pattern_match/test.py

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
import infamy
1111
import time
1212

13+
TEST_MESSAGES = [
14+
"ERROR: Connection failed on interface eth0",
15+
"CRITICAL: System temperature high",
16+
"Status update from router1: link up",
17+
"Status update from router42: link down",
18+
"INFO: Normal operation message",
19+
"DEBUG: Verbose logging enabled",
20+
]
21+
1322
with infamy.Test() as test:
1423
with test.step("Set up topology and attach to target DUT"):
1524
env = infamy.Env()
@@ -52,52 +61,49 @@
5261
}
5362
})
5463

64+
time.sleep(2)
65+
5566
with test.step("Send test messages with various patterns"):
56-
tgtssh.runsh("logger -t test -p daemon.info 'ERROR: Connection failed on interface eth0'")
57-
tgtssh.runsh("logger -t test -p daemon.info 'CRITICAL: System temperature high'")
58-
tgtssh.runsh("logger -t test -p daemon.info 'Status update from router1: link up'")
59-
tgtssh.runsh("logger -t test -p daemon.info 'Status update from router42: link down'")
60-
tgtssh.runsh("logger -t test -p daemon.info 'INFO: Normal operation message'")
61-
tgtssh.runsh("logger -t test -p daemon.info 'DEBUG: Verbose logging enabled'")
62-
time.sleep(1)
67+
for message in TEST_MESSAGES:
68+
tgtssh.runsh(f"logger -t test -p daemon.info '{message}'")
69+
time.sleep(2)
6370

6471
with test.step("Verify errors log contains ERROR and CRITICAL messages"):
65-
rc = tgtssh.runsh("grep -c 'ERROR\\|CRITICAL' /var/log/errors 2>/dev/null")
66-
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
67-
if count != 2:
68-
test.fail(f"Expected 2 ERROR/CRITICAL messages in /var/log/errors, got {count}")
72+
rc = tgtssh.runsh("cat /var/log/errors 2>/dev/null")
73+
log_content = rc.stdout if rc.returncode == 0 else ""
74+
75+
error_messages = [msg for msg in TEST_MESSAGES if "ERROR" in msg or "CRITICAL" in msg]
76+
missing = [msg for msg in error_messages if msg not in log_content]
77+
if missing:
78+
test.fail(f"Missing error messages in /var/log/errors: {missing}")
6979

7080
# Verify it does NOT contain other messages
71-
rc = tgtssh.runsh("grep -c 'router1\\|Normal operation\\|Verbose' /var/log/errors 2>/dev/null")
72-
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
73-
if count != 0:
74-
test.fail(f"Expected 0 non-error messages in /var/log/errors, got {count}")
81+
non_error_messages = [msg for msg in TEST_MESSAGES if "ERROR" not in msg and "CRITICAL" not in msg]
82+
found = [msg for msg in non_error_messages if msg in log_content]
83+
if found:
84+
test.fail(f"Found unwanted messages in /var/log/errors: {found}")
7585

7686
with test.step("Verify routers log contains matching router[0-9]+ pattern"):
77-
rc = tgtssh.runsh("grep -c 'router[0-9]\\+' /var/log/routers 2>/dev/null")
78-
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
79-
if count != 2:
80-
test.fail(f"Expected 2 router messages in /var/log/routers, got {count}")
87+
rc = tgtssh.runsh("cat /var/log/routers 2>/dev/null")
88+
log_content = rc.stdout if rc.returncode == 0 else ""
8189

82-
# Verify both router1 and router42 are present
83-
rc = tgtssh.runsh("grep -q 'router1' /var/log/routers 2>/dev/null")
84-
if rc.returncode != 0:
85-
test.fail("Expected router1 message in /var/log/routers")
86-
87-
rc = tgtssh.runsh("grep -q 'router42' /var/log/routers 2>/dev/null")
88-
if rc.returncode != 0:
89-
test.fail("Expected router42 message in /var/log/routers")
90+
router_messages = [msg for msg in TEST_MESSAGES if "router1" in msg or "router42" in msg]
91+
missing = [msg for msg in router_messages if msg not in log_content]
92+
if missing:
93+
test.fail(f"Missing router messages in /var/log/routers: {missing}")
9094

9195
# Verify it does NOT contain error or normal messages
92-
rc = tgtssh.runsh("grep -c 'ERROR\\|CRITICAL\\|Normal operation\\|Verbose' /var/log/routers 2>/dev/null")
93-
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
94-
if count != 0:
95-
test.fail(f"Expected 0 non-router messages in /var/log/routers, got {count}")
96+
non_router_messages = [msg for msg in TEST_MESSAGES if "router" not in msg]
97+
found = [msg for msg in non_router_messages if msg in log_content]
98+
if found:
99+
test.fail(f"Found unwanted messages in /var/log/routers: {found}")
96100

97101
with test.step("Verify all-messages log contains all test messages"):
98-
rc = tgtssh.runsh("grep -c 'test' /var/log/all-messages 2>/dev/null")
99-
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
100-
if count != 6:
101-
test.fail(f"Expected 6 total messages in /var/log/all-messages, got {count}")
102+
rc = tgtssh.runsh("cat /var/log/all-messages 2>/dev/null")
103+
log_content = rc.stdout if rc.returncode == 0 else ""
104+
105+
missing = [msg for msg in TEST_MESSAGES if msg not in log_content]
106+
if missing:
107+
test.fail(f"Missing messages in /var/log/all-messages: {missing}")
102108

103109
test.succeed()

0 commit comments

Comments
 (0)