Skip to content

Commit 4aac40d

Browse files
committed
manual test case improved
1 parent 6d28f4a commit 4aac40d

21 files changed

+677
-1445
lines changed

Makefile

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ help:
2020
@echo " make install Install in production mode"
2121
@echo " make install-dev Install with test dependencies"
2222
@echo " make install-dev-tools Install linters, formatters & pre-commit hooks"
23-
@echo ""
23+
@echo ""e
2424
@echo "$(YELLOW)What Gets Installed:$(NC)"
2525
@echo " Package | install | install-dev | install-dev-tools"
2626
@echo " ----------------|---------|-------------|------------------"
@@ -46,8 +46,8 @@ help:
4646
@echo " make test-all Run ALL tests including E2E (AWS_PROFILE=china)"
4747
@echo " make test-coverage Run tests with HTML coverage report"
4848
@echo " make test-manual Run 17 core manual test scenarios (~2.5 hours)"
49-
@echo " make test-gap Run 11 gap + advanced test scenarios (~3 hours)"
50-
@echo " make test-all-manual Run ALL manual tests (core + gap + advanced, ~5.5 hours)"
49+
@echo " make test-gap Run 9 gap + advanced test scenarios (~2 hours)"
50+
@echo " make test-all-manual Run ALL manual tests (core + gap + advanced, ~4.5 hours)"
5151
@echo ""
5252
@echo "$(GREEN)Production Simulation (Long-Running):$(NC)"
5353
@echo " make test-prod-sim-2h Run 2-hour production simulation (quick validation)"
@@ -159,14 +159,16 @@ test-manual:
159159

160160
test-gap:
161161
@echo "$(BLUE)Running gap + advanced test scenarios...$(NC)"
162-
@echo "$(YELLOW)This runs 11 test scenarios (~3 hours)$(NC)"
163-
@echo "$(YELLOW)Gap tests (18-22): env vars, all sources, deferred deletion, crash recovery, registry cleanup$(NC)"
164-
@echo "$(YELLOW)Advanced tests (23,25-29): config validation, concurrency, security, performance, integration$(NC)"
162+
@echo "$(YELLOW)This runs 9 test scenarios (~2 hours)$(NC)"
163+
@echo "$(YELLOW)Tests 1-5: All sources, deferred deletion, crash recovery, registry cleanup, env vars$(NC)"
164+
@echo "$(YELLOW)Tests 6-9: Config validation, security, full integration, production sim$(NC)"
165+
@echo "$(YELLOW)Note: Tests 25 (concurrent), 26 (resource limits), 28 (performance) removed$(NC)"
166+
@echo "$(YELLOW) Test 9 (production simulation) provides superior coverage for all removed tests$(NC)"
165167
./scripts/testing/gap-tests/run_gap_tests.sh
166168
@echo "$(GREEN)✓ Gap + advanced tests complete$(NC)"
167169

168170
test-all-manual: test-manual test-gap
169-
@echo "$(GREEN)✓ All manual tests complete (17 core + 5 gap + 6 advanced = 28 tests)$(NC)"
171+
@echo "$(GREEN)✓ All manual tests complete (17 core + 9 gap/advanced = 26 tests)$(NC)"
170172

171173
# ==================== Production Simulation Tests ====================
172174

@@ -179,7 +181,12 @@ test-prod-sim-2h:
179181
@echo "$(YELLOW)Vehicle ID: VEHICLE-PROD-TEST-2H$(NC)"
180182
@echo "$(YELLOW)Cycles: ~1 cycle (100 min per cycle)$(NC)"
181183
@echo ""
182-
./scripts/testing/gap-tests/run_production_simulation.sh config/config.yaml VEHICLE-PROD-TEST-2H 2
184+
@if ! sudo -n true 2>/dev/null; then \
185+
echo "$(YELLOW)Note: This test requires passwordless sudo. Run once:$(NC)"; \
186+
echo "$(YELLOW) sudo ./scripts/deployment/setup_test_sudo.sh$(NC)"; \
187+
echo ""; \
188+
fi
189+
./scripts/testing/gap-tests/run_production_simulation.sh config/config.yaml VEHICLE-PROD-TEST-2H 2 true
183190
@echo "$(GREEN)✓ 2-hour production simulation complete$(NC)"
184191

185192
test-prod-sim-8h:
@@ -192,7 +199,12 @@ test-prod-sim-8h:
192199
@echo "$(YELLOW)Cycles: ~5 cycles (100 min per cycle)$(NC)"
193200
@echo "$(YELLOW)Expected files: 20,000 - 40,000$(NC)"
194201
@echo ""
195-
./scripts/testing/gap-tests/run_production_simulation.sh config/config.yaml VEHICLE-PROD-TEST-8H 8
202+
@if ! sudo -n true 2>/dev/null; then \
203+
echo "$(YELLOW)Note: This test requires passwordless sudo. Run once:$(NC)"; \
204+
echo "$(YELLOW) sudo ./scripts/deployment/setup_test_sudo.sh$(NC)"; \
205+
echo ""; \
206+
fi
207+
./scripts/testing/gap-tests/run_production_simulation.sh config/config.yaml VEHICLE-PROD-TEST-8H 8 true
196208
@echo "$(GREEN)✓ 8-hour production simulation complete$(NC)"
197209

198210
test-prod-sim-24h:
@@ -205,7 +217,12 @@ test-prod-sim-24h:
205217
@echo "$(YELLOW)Cycles: ~14 cycles (100 min per cycle)$(NC)"
206218
@echo "$(YELLOW)Expected files: 60,000 - 120,000$(NC)"
207219
@echo ""
208-
./scripts/testing/gap-tests/run_production_simulation.sh config/config.yaml VEHICLE-PROD-TEST-24H 24
220+
@if ! sudo -n true 2>/dev/null; then \
221+
echo "$(YELLOW)Note: This test requires passwordless sudo. Run once:$(NC)"; \
222+
echo "$(YELLOW) sudo ./scripts/deployment/setup_test_sudo.sh$(NC)"; \
223+
echo ""; \
224+
fi
225+
./scripts/testing/gap-tests/run_production_simulation.sh config/config.yaml VEHICLE-PROD-TEST-24H 24 true
209226
@echo "$(GREEN)✓ 24-hour production simulation complete$(NC)"
210227

211228
# ==================== Code Quality ====================
@@ -366,9 +383,8 @@ info:
366383
@echo " Integration: 90 tests (~35 sec)"
367384
@echo " E2E: 60 tests (~7.5 min)"
368385
@echo " Manual (core): 17 scenarios (~2.5 hours)"
369-
@echo " Manual (gap): 5 scenarios (~30 min)"
370-
@echo " Manual (adv): 6 scenarios (~2.5 hours)"
371-
@echo " Manual (total): 28 scenarios (~5.5 hours)"
386+
@echo " Manual (gap): 9 scenarios (~2 hours)"
387+
@echo " Manual (total): 26 scenarios (~4.5 hours)"
372388

373389
version:
374390
@echo "TVM Upload System v2.1.0"

PASSWORDLESS_SUDO_SETUP.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Passwordless Sudo Setup for Production Simulation Test
2+
3+
## Problem
4+
The production simulation test (Test 9) asks for sudo password multiple times during execution because it needs to:
5+
- Manipulate network with `iptables` (simulate WiFi on/off)
6+
- Add network latency with `tc` (simulate poor connectivity)
7+
- Kill processes with `kill` (simulate crashes)
8+
9+
## Solution: One-Time Setup
10+
11+
Run this **ONCE** to enable passwordless sudo for test commands:
12+
13+
```bash
14+
sudo ./scripts/deployment/setup_test_sudo.sh
15+
```
16+
17+
This creates `/etc/sudoers.d/tvm-test` with rules allowing your user to run specific commands without password.
18+
19+
## What Commands Are Allowed
20+
21+
Only these specific commands will be passwordless:
22+
- `/usr/sbin/iptables` and `/sbin/iptables`
23+
- `/usr/sbin/tc` and `/sbin/tc`
24+
- `/usr/bin/kill` and `/bin/kill`
25+
- `/usr/bin/systemctl stop tvm-upload`
26+
27+
**No other sudo commands are affected** - this is safe and targeted.
28+
29+
## Usage After Setup
30+
31+
### Run Production Simulation Without Prompts
32+
33+
```bash
34+
# 2-hour test (no password prompts)
35+
make test-prod-sim-2h
36+
37+
# 8-hour test (no password prompts)
38+
make test-prod-sim-8h
39+
40+
# 24-hour test (no password prompts)
41+
make test-prod-sim-24h
42+
43+
# Or directly with skip prompts flag
44+
./scripts/testing/gap-tests/run_production_simulation.sh config/config.yaml vehicle-TEST 2 true
45+
# ^
46+
# skip prompts
47+
```
48+
49+
### Manual Usage (With Prompts)
50+
51+
If you don't run the setup, you can still run the test but will be prompted for password:
52+
53+
```bash
54+
# Will ask for password when needed
55+
./scripts/testing/gap-tests/run_production_simulation.sh config/config.yaml vehicle-TEST 2
56+
```
57+
58+
## Verify Setup
59+
60+
Check if passwordless sudo is working:
61+
62+
```bash
63+
# This should work without password after setup
64+
sudo -n iptables -L > /dev/null 2>&1 && echo "✓ Passwordless sudo working" || echo "✗ Setup needed"
65+
```
66+
67+
## Remove Passwordless Sudo
68+
69+
If you want to remove this configuration later:
70+
71+
```bash
72+
sudo rm /etc/sudoers.d/tvm-test
73+
```
74+
75+
## Security Notes
76+
77+
- ✅ Only allows specific commands needed for testing
78+
- ✅ Only allows for your user account
79+
- ✅ Uses `/etc/sudoers.d/` which is the recommended approach
80+
- ✅ Validated with `visudo -c` before installation
81+
- ✅ No shell access or arbitrary command execution
82+
83+
This is **safe for development/test environments** where you need to run network simulation tests frequently.
84+
85+
**⚠️ NOT recommended for production servers** - only use on development machines or dedicated test systems.
86+
87+
## Troubleshooting
88+
89+
### "Invalid sudoers syntax" error
90+
The setup script validates syntax before applying. If you see this error:
91+
1. Check you're running on Linux (not macOS/BSD)
92+
2. Ensure `visudo` is installed
93+
3. Report the issue
94+
95+
### Still asking for password
96+
1. Verify the file exists: `ls -l /etc/sudoers.d/tvm-test`
97+
2. Check permissions: should be `0440`
98+
3. Check ownership: should be `root:root`
99+
4. Verify your username matches: `grep $USER /etc/sudoers.d/tvm-test`
100+
101+
### "This test requires passwordless sudo" error
102+
This means you ran with `SKIP_PROMPTS=true` but haven't set up passwordless sudo yet:
103+
```bash
104+
sudo ./scripts/deployment/setup_test_sudo.sh
105+
```
106+
107+
---
108+
109+
**Created**: 2025-11-14
110+
**Last Updated**: 2025-11-14

0 commit comments

Comments
 (0)