summaryrefslogtreecommitdiff
path: root/scripts/testing/README.org
blob: e58a89edcac2a9acd98bdc9c22dade8f3be62bb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#+TITLE: ArchSetup Testing Infrastructure
#+AUTHOR: Craig Jennings
#+DATE: 2025-11-08

* Overview

This directory contains the complete testing infrastructure for archsetup, built on QEMU/KVM virtualization. It provides automated, reproducible testing of the archsetup installation script in isolated virtual machines.

** Philosophy

*Realism over speed.* We use full VMs (not containers) to test everything archsetup does: user creation, systemd services, X11/DWM, hardware drivers, and boot process.

** Architecture

Uses direct QEMU with user-mode networking and SSH port forwarding. No libvirt/virsh dependency. Base VM creation is fully automated via the archangel ISO (unattended Arch Linux installer).

* Quick Start

** One-Time Setup

#+begin_src bash
# Install required packages (qemu-full, sshpass, edk2-ovmf, socat)
./scripts/testing/setup-testing-env.sh

# Copy an archangel ISO to vm-images/
cp /path/to/archzfs-*.iso vm-images/

# Create the base VM (fully automated, no manual steps)
./scripts/testing/create-base-vm.sh
#+end_src

** Run a Test

#+begin_src bash
# Test the current archsetup script
./scripts/testing/run-test.sh

# Test a specific version
./scripts/testing/run-test.sh --script /path/to/archsetup

# Keep VM running for debugging
./scripts/testing/run-test.sh --keep
#+end_src

** Debug Interactively

#+begin_src bash
# Launch base VM with graphical display (copy-on-write overlay, safe)
./scripts/testing/debug-vm.sh --base

# Use existing test disk directly
./scripts/testing/debug-vm.sh vm-images/some-disk.qcow2
#+end_src

** Clean Up

#+begin_src bash
# Interactive cleanup (prompts for confirmation)
./scripts/testing/cleanup-tests.sh

# Keep last 10 test results
./scripts/testing/cleanup-tests.sh --keep 10

# Force cleanup without prompts
./scripts/testing/cleanup-tests.sh --force
#+end_src

* Scripts

** setup-testing-env.sh

*Purpose:* One-time setup of testing infrastructure

*What it does:*
- Installs QEMU/KVM, sshpass, OVMF firmware, and socat
- Verifies KVM support
- Creates directories for artifacts

*When to run:* Once per development machine

** create-base-vm.sh

*Purpose:* Create the "golden image" minimal Arch VM

*What it does:*
- Boots an archangel ISO in QEMU with SSH port forwarding
- Waits for SSH to become available on the live ISO
- Copies archangel config file (=archsetup-test.conf=) into the VM
- Runs =archangel --config-file= for fully unattended installation
- Boots the installed system and verifies SSH/services
- Creates a "clean-install" qemu-img snapshot

*When to run:* Once (or when you want to refresh base image)

*Result:* Base VM image at =vm-images/archsetup-base.qcow2= with "clean-install" snapshot

** run-test.sh

*Purpose:* Execute a full test run of archsetup

*What it does:*
- Reverts base VM to clean-install snapshot
- Boots the VM via QEMU
- Transfers archsetup script and dotfiles via git bundle
- Executes archsetup inside VM
- Captures logs and results
- Runs comprehensive validation checks
- Generates test report
- Reverts to clean snapshot (unless =--keep=)

*When to run:* Every time you want to test archsetup

*Results:* Saved to =test-results/TIMESTAMP/=
- =test.log= - Complete log output
- =test-report.txt= - Summary of results
- =archsetup-*.log= - Log from archsetup script
- =*.txt= - Package lists from VM

** debug-vm.sh

*Purpose:* Launch VM for interactive debugging

*What it does:*
- Creates a copy-on-write overlay disk (instant, protects base image)
- Boots QEMU with GTK graphical display
- Provides SSH connection info
- Cleans up overlay when the GTK window is closed

*When to run:* When you need to manually test or debug

*Connect via:*
- GTK window (opens automatically)
- SSH: =sshpass -p 'archsetup' ssh -p 2222 root@localhost=

** cleanup-tests.sh

*Purpose:* Clean up old test VMs and artifacts

*What it does:*
- Stops running QEMU processes
- Kills orphaned QEMU processes
- Removes temporary disk images (overlays, test clones)
- Keeps last N test results, deletes rest

*When to run:* Periodically to free disk space

** archsetup-test.conf

*Purpose:* Archangel config file for automated base VM creation

Defines the base system: btrfs filesystem, no encryption, SSH enabled, root password "archsetup". Used by =create-base-vm.sh=.

* Directory Structure

#+begin_example
archsetup/
├── scripts/
│   └── testing/
│       ├── README.org                    # This file
│       ├── setup-testing-env.sh          # Setup infrastructure
│       ├── create-base-vm.sh             # Create base VM (automated)
│       ├── run-test.sh                   # Run tests
│       ├── run-test-baremetal.sh         # Bare-metal testing
│       ├── debug-vm.sh                   # Interactive debugging
│       ├── cleanup-tests.sh              # Clean up
│       ├── archsetup-test.conf           # Archangel config for test VMs
│       └── lib/
│           ├── logging.sh                # Logging utilities
│           ├── vm-utils.sh               # QEMU VM management
│           ├── validation.sh             # Test validation checks
│           └── network-diagnostics.sh    # Network pre-flight checks
├── vm-images/                            # VM disk images (gitignored)
│   ├── archsetup-base.qcow2             # Golden image with snapshot
│   ├── archzfs-*.iso                    # Archangel ISO
│   ├── OVMF_VARS.fd                     # UEFI variables (per-VM)
│   └── debug-overlay-*.qcow2            # Temp debug overlays
├── test-results/                         # Test results (gitignored)
│   └── TIMESTAMP/
│       ├── test.log
│       ├── test-report.txt
│       └── archsetup-*.log
└── docs/
    ├── testing-strategy.org              # Complete strategy doc
    └── archangel-vm-testing-guide.org    # Archangel integration guide
#+end_example

* Configuration

** VM Specifications

All test VMs use:
- *CPUs:* 4 vCPUs
- *RAM:* 4GB
- *Disk:* 50GB (thin provisioned qcow2)
- *Network:* User-mode networking with SSH port forwarding (localhost:2222)
- *Boot:* UEFI (via OVMF firmware)
- *Display:* Headless (automated) or GTK (debug)

Set environment variables to customize:
#+begin_src bash
VM_CPUS=8 VM_RAM=8192 ./scripts/testing/run-test.sh
#+end_src

** Base VM Specifications

The base VM is created automatically by archangel with:
- Btrfs filesystem (no encryption)
- GRUB bootloader
- OpenSSH server (root login enabled)
- NetworkManager
- Root password: "archsetup"

* Validation Checks

Each test run performs these validation checks:

** Critical (Must Pass)
1. archsetup exits with code 0
2. User 'cjennings' was created
3. Dotfiles are stowed (symlinks exist)
4. yay (AUR helper) is installed
5. DWM or Hyprland is configured

** Additional
- All expected packages installed
- systemd services enabled
- Firewall configured
- Developer tools present

* Troubleshooting

** VM fails to start

Check if KVM is available and port 2222 is free:
#+begin_src bash
ls -l /dev/kvm
ss -tln | grep 2222
#+end_src

** SSH connection refused

Wait longer for VM to boot, or check serial log:
#+begin_src bash
cat vm-images/qemu-serial.log
#+end_src

** KVM not available

Check if virtualization is enabled in BIOS and KVM modules loaded:
#+begin_src bash
ls -l /dev/kvm
sudo modprobe kvm-amd   # or kvm-intel
lsmod | grep kvm
#+end_src

** Disk space issues

Clean up old tests:
#+begin_src bash
./scripts/testing/cleanup-tests.sh --force
du -sh vm-images/ test-results/
#+end_src

** Port 2222 already in use

Another QEMU instance may be running:
#+begin_src bash
# Find what's using the port
ss -tlnp | grep 2222

# Kill orphaned QEMU processes
pkill -f "qemu-system.*archsetup-test"
#+end_src

* Future Enhancements

** Planned Improvements
- [ ] Parallel test execution (multiple VMs on different ports)
- [ ] Screenshot capture of X11/Wayland desktop
- [ ] CI/CD integration (GitHub Actions / GitLab CI)
- [ ] Performance benchmarking over time

** Test Scenarios
- [ ] Idempotency test (run archsetup twice)
- [ ] Network failure recovery
- [ ] Offline installation (local package cache)
- [ ] Different hardware profiles (CPU/RAM variations)

* References

- [[file:../../docs/testing-strategy.org][Testing Strategy Document]]
- [[file:../../docs/archangel-vm-testing-guide.org][Archangel VM Testing Guide]]
- [[https://wiki.archlinux.org/title/QEMU][Arch Wiki: QEMU]]
- [[file:../../archsetup][Main archsetup script]]
- [[file:../../todo.org][Project TODO]]