run.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. #!/usr/bin/env node
  2. "use strict";
  3. process.on("unhandledRejection", exn => { throw exn; });
  4. var TIMEOUT_EXTRA_FACTOR = +process.env.TIMEOUT_EXTRA_FACTOR || 1;
  5. var MAX_PARALLEL_TESTS = +process.env.MAX_PARALLEL_TESTS || 4;
  6. var TEST_NAME = process.env.TEST_NAME;
  7. const TEST_RELEASE_BUILD = +process.env.TEST_RELEASE_BUILD;
  8. const RUN_SLOW_TESTS = +process.env.RUN_SLOW_TESTS;
  9. const VERBOSE = false;
  10. const LOG_SCREEN = false;
  11. try
  12. {
  13. var V86 = require(`../../build/${TEST_RELEASE_BUILD ? "libv86" : "libv86-debug"}.js`).V86;
  14. }
  15. catch(e)
  16. {
  17. console.error("Failed to import build/libv86-debug.js. Run `make build/libv86-debug.js first.");
  18. process.exit(1);
  19. }
  20. const assert = require("assert").strict;
  21. var cluster = require("cluster");
  22. var os = require("os");
  23. var fs = require("fs");
  24. var root_path = __dirname + "/../..";
  25. var SCREEN_WIDTH = 80;
  26. function get_line(screen, y)
  27. {
  28. return screen.subarray(y * SCREEN_WIDTH, (y + 1) * SCREEN_WIDTH);
  29. }
  30. function line_to_text(screen, y)
  31. {
  32. return bytearray_to_string(get_line(screen, y));
  33. }
  34. function string_to_bytearray(str)
  35. {
  36. return new Uint8Array(str.split("").map(chr => chr.charCodeAt(0)));
  37. }
  38. function bytearray_to_string(arr)
  39. {
  40. return String.fromCharCode.apply(String, arr).replace(/[\x00-\x08\x0b-\x1f\x7f\x80-\xff]/g, " ");
  41. }
  42. function screen_to_text(s)
  43. {
  44. var result = [];
  45. result.push("+==================================== SCREEN ====================================+");
  46. for(var i = 0; i < 25; i++)
  47. {
  48. var line = line_to_text(s, i);
  49. result.push("|" + line + "|");
  50. }
  51. result.push("+================================================================================+");
  52. return result.join("\n");
  53. }
  54. function send_work_to_worker(worker, message)
  55. {
  56. if(current_test < tests.length)
  57. {
  58. worker.send(tests[current_test]);
  59. current_test++;
  60. }
  61. else
  62. {
  63. worker.disconnect();
  64. }
  65. }
  66. if(cluster.isMaster)
  67. {
  68. var tests = [
  69. {
  70. name: "FreeDOS boot",
  71. fda: root_path + "/images/freedos722.img",
  72. timeout: 20,
  73. expected_texts: [
  74. "Welcome to FreeDOS",
  75. ],
  76. },
  77. {
  78. name: "FreeDOS boot with Bochs BIOS",
  79. fda: root_path + "/images/freedos722.img",
  80. timeout: 20,
  81. alternative_bios: true,
  82. expected_texts: [
  83. "Welcome to FreeDOS",
  84. ],
  85. },
  86. {
  87. name: "Windows 1.01 boot",
  88. fda: root_path + "/images/windows101.img",
  89. timeout: 10,
  90. expect_graphical_mode: true,
  91. expect_mouse_registered: true,
  92. },
  93. {
  94. name: "Sol OS",
  95. fda: root_path + "/images/os8.img",
  96. timeout: 20,
  97. expect_graphical_mode: true,
  98. expect_mouse_registered: true,
  99. actions: [
  100. {
  101. on_text: " or press",
  102. run: "\n"
  103. },
  104. ],
  105. },
  106. {
  107. name: "Snowdrop",
  108. skip_if_disk_image_missing: true,
  109. fda: root_path + "/images/snowdrop.img",
  110. timeout: 30,
  111. expect_graphical_mode: true,
  112. expect_mouse_registered: true,
  113. actions: [
  114. {
  115. on_text: "[Snowdrop OS snowshell]:",
  116. run: "desktop\n"
  117. },
  118. ],
  119. },
  120. {
  121. name: "Linux",
  122. cdrom: root_path + "/images/linux.iso",
  123. timeout: 90,
  124. expected_texts: [
  125. "/root%",
  126. "test passed",
  127. ],
  128. actions: [
  129. {
  130. on_text: "/root%",
  131. run: "cd tests; ./test-i386 > emu.test; diff emu.test reference.test && echo test pas''sed || echo failed\n",
  132. },
  133. ],
  134. },
  135. {
  136. name: "Windows XP CD",
  137. skip_if_disk_image_missing: true,
  138. cdrom: root_path + "/images/experimental/VirtualXP.iso",
  139. memory_size: 512 * 1024 * 1024,
  140. timeout: 600,
  141. expect_graphical_mode: true,
  142. expect_graphical_size: [800, 600],
  143. expect_mouse_registered: true,
  144. },
  145. {
  146. name: "Windows XP HD",
  147. skip_if_disk_image_missing: true,
  148. hda: root_path + "/images/experimental/copy_winxp_lite-from-pixelsuft.img",
  149. memory_size: 512 * 1024 * 1024,
  150. timeout: 300,
  151. expect_graphical_mode: true,
  152. expect_graphical_size: [800, 600],
  153. expect_mouse_registered: true,
  154. },
  155. {
  156. name: "Windows 2000",
  157. skip_if_disk_image_missing: true,
  158. hda: root_path + "/images/windows2k.img",
  159. memory_size: 512 * 1024 * 1024,
  160. timeout: 300,
  161. expect_graphical_mode: true,
  162. expect_graphical_size: [1024, 768],
  163. expect_mouse_registered: true,
  164. },
  165. {
  166. name: "Windows NT 4.0",
  167. skip_if_disk_image_missing: true,
  168. hda: root_path + "/images/winnt4_noacpi.img",
  169. memory_size: 512 * 1024 * 1024,
  170. timeout: 60,
  171. expect_graphical_mode: true,
  172. expect_graphical_size: [1024, 768],
  173. expect_mouse_registered: true,
  174. cpuid_level: 2,
  175. },
  176. {
  177. name: "Windows NT 3.1",
  178. skip_if_disk_image_missing: true,
  179. hda: root_path + "/images/winnt31.img",
  180. memory_size: 256 * 1024 * 1024,
  181. timeout: 60,
  182. expect_graphical_mode: true,
  183. expect_graphical_size: [640, 480],
  184. expect_mouse_registered: true,
  185. },
  186. //{
  187. // name: "Windows 98",
  188. // skip_if_disk_image_missing: true,
  189. // hda: root_path + "/images/windows98.img",
  190. // timeout: 60,
  191. // expect_graphical_mode: true,
  192. // expect_graphical_size: [800, 600],
  193. // expect_mouse_registered: true,
  194. // failure_allowed: true,
  195. //},
  196. {
  197. name: "Windows 95",
  198. skip_if_disk_image_missing: true,
  199. hda: root_path + "/images/w95.img",
  200. timeout: 120,
  201. expect_graphical_mode: true,
  202. expect_graphical_size: [1024, 768],
  203. expect_mouse_registered: true,
  204. failure_allowed: true,
  205. },
  206. {
  207. name: "Oberon",
  208. skip_if_disk_image_missing: true,
  209. hda: root_path + "/images/oberon.img",
  210. timeout: 30,
  211. expect_graphical_mode: true,
  212. expect_mouse_registered: true,
  213. },
  214. {
  215. name: "Linux 3",
  216. skip_if_disk_image_missing: true,
  217. cdrom: root_path + "/images/linux3.iso",
  218. timeout: 200,
  219. expected_texts: [
  220. "test passed",
  221. ],
  222. actions: [
  223. {
  224. on_text: "~%",
  225. run: "head -c 10000 /dev/urandom > rand; echo test pas''sed\n",
  226. after: 1000,
  227. },
  228. ],
  229. },
  230. {
  231. name: "Linux 3 reboot",
  232. cdrom: root_path + "/images/linux3.iso",
  233. timeout: 90,
  234. expected_texts: [
  235. "~%",
  236. "SeaBIOS ",
  237. "~%",
  238. ],
  239. actions: [
  240. {
  241. on_text: "~%",
  242. run: "reboot\n",
  243. },
  244. ],
  245. },
  246. {
  247. name: "KolibriOS",
  248. fda: root_path + "/images/kolibri.img",
  249. timeout: 120,
  250. expect_graphical_mode: true,
  251. expect_mouse_registered: true,
  252. },
  253. {
  254. name: "Linux with Bochs BIOS",
  255. cdrom: root_path + "/images/linux.iso",
  256. timeout: 90,
  257. expected_texts: [
  258. "/root%",
  259. "test passed",
  260. ],
  261. alternative_bios: true,
  262. actions: [
  263. {
  264. on_text: "/root%",
  265. run: "cd tests; ./test-i386 > emu.test; diff emu.test reference.test && echo test pas''sed || echo failed\n",
  266. },
  267. ],
  268. },
  269. {
  270. name: "MS-DOS",
  271. skip_if_disk_image_missing: true,
  272. hda: root_path + "/images/msdos.img",
  273. timeout: 90,
  274. expected_texts: [
  275. "C:\\>",
  276. ],
  277. },
  278. {
  279. name: "MS-DOS (hard disk + floppy disk)",
  280. skip_if_disk_image_missing: true,
  281. hda: root_path + "/images/msdos.img",
  282. fda: root_path + "/images/kolibri.img",
  283. boot_order: 0x132,
  284. timeout: 90,
  285. actions: [
  286. { on_text: "C:\\>", run: "a:\n" },
  287. ],
  288. expected_texts: [
  289. "A:\\>",
  290. ],
  291. },
  292. {
  293. name: "Linux 4",
  294. skip_if_disk_image_missing: true,
  295. cdrom: root_path + "/images/linux4.iso",
  296. timeout: 200,
  297. expected_texts: [
  298. "~%",
  299. ],
  300. expected_serial_text: [
  301. "Files send via emulator appear in",
  302. ],
  303. expect_mouse_registered: true,
  304. },
  305. {
  306. name: "Linux bzImage",
  307. bzimage: root_path + "/images/buildroot-bzimage.bin",
  308. cmdline: "auto",
  309. timeout: 200,
  310. expected_texts: [
  311. "~%",
  312. ],
  313. expected_serial_text: [
  314. "Files send via emulator appear in",
  315. ],
  316. expect_mouse_registered: true,
  317. },
  318. {
  319. name: "Linux with bzImage from filesystem",
  320. bzimage_initrd_from_filesystem: true,
  321. filesystem: {
  322. basefs: root_path + "/build/integration-test-fs/fs.json",
  323. baseurl: root_path + "/build/integration-test-fs/flat/",
  324. },
  325. cmdline: "auto",
  326. timeout: 200,
  327. expected_texts: [
  328. "~%",
  329. ],
  330. expected_serial_text: [
  331. "Files send via emulator appear in",
  332. ],
  333. expect_mouse_registered: true,
  334. },
  335. {
  336. name: "QNX",
  337. skip_if_disk_image_missing: true,
  338. fda: root_path + "/images/qnx-demo-network-4.05.img",
  339. timeout: 300,
  340. expect_mouse_registered: true,
  341. expect_graphical_mode: true,
  342. expect_graphical_size: [640, 480],
  343. actions: [
  344. { run: " ", after: 30 * 1000 },
  345. { run: " ", after: 15 * 1000 },
  346. { run: " ", after: 15 * 1000 },
  347. { run: " ", after: 15 * 1000 },
  348. { run: " ", after: 15 * 1000 },
  349. { run: " ", after: 15 * 1000 },
  350. { run: " ", after: 15 * 1000 },
  351. ],
  352. },
  353. {
  354. name: "OpenBSD Floppy",
  355. fda: root_path + "/images/openbsd-floppy.img",
  356. timeout: 180,
  357. expected_texts: ["(I)nstall, (U)pgrade or (S)hell"],
  358. },
  359. {
  360. name: "OpenBSD",
  361. skip_if_disk_image_missing: true,
  362. hda: root_path + "/images/openbsd.img",
  363. timeout: 300,
  364. actions: [
  365. {
  366. on_text: "boot>",
  367. run: "boot -c\n",
  368. },
  369. {
  370. on_text: "UKC>",
  371. run: "disable mpbios\nexit\n",
  372. },
  373. {
  374. on_text: "login:",
  375. run: "root\n",
  376. },
  377. {
  378. on_text: "Password:",
  379. run: "root\n",
  380. },
  381. ],
  382. expected_texts: ["nyu# "],
  383. },
  384. {
  385. name: "Windows 3.0",
  386. slow: 1,
  387. skip_if_disk_image_missing: true,
  388. timeout: 10 * 60,
  389. cdrom: root_path + "/images/Win30.iso",
  390. expected_texts: [
  391. "Press any key to continue",
  392. " **************************************************",
  393. ],
  394. expect_graphical_mode: true,
  395. expect_mouse_registered: true,
  396. actions: [
  397. {
  398. on_text: "Press any key to continue . . .",
  399. after: 1000,
  400. run: "x",
  401. },
  402. {
  403. on_text: " **************************************************",
  404. after: 1000,
  405. run: "x",
  406. },
  407. {
  408. on_text: "C> ",
  409. after: 1000,
  410. run: "win\n",
  411. },
  412. ],
  413. },
  414. {
  415. name: "Windows 3.1",
  416. skip_if_disk_image_missing: true,
  417. timeout: 2 * 60,
  418. hda: root_path + "/images/win31.img",
  419. expect_graphical_mode: true,
  420. expect_graphical_size: [1024, 768],
  421. expect_mouse_registered: true,
  422. expected_texts: [
  423. "MODE prepare code page function completed",
  424. ],
  425. },
  426. {
  427. name: "FreeBSD",
  428. skip_if_disk_image_missing: true,
  429. timeout: 15 * 60,
  430. hda: root_path + "/images/freebsd.img",
  431. expected_texts: [
  432. "FreeBSD/i386 (nyu) (ttyv0)",
  433. "root@nyu:~ #",
  434. ],
  435. actions: [
  436. {
  437. on_text: " Autoboot in",
  438. run: "\n",
  439. },
  440. {
  441. // workaround for freebsd not accepting key inputs just before the boot prompt
  442. // (probably needs delay between keydown and keyup)
  443. on_text: "FreeBSD/i386 (nyu) (ttyv0)",
  444. run: "\x08", // backspace to avoid messing with login prompt
  445. },
  446. {
  447. on_text: "login:",
  448. after: 1000,
  449. run: "root\n",
  450. },
  451. {
  452. on_text: "Password:",
  453. after: 1000,
  454. run: "\n",
  455. },
  456. ],
  457. },
  458. {
  459. name: "FreeBSD cdrom",
  460. skip_if_disk_image_missing: true,
  461. slow: 1,
  462. timeout: 10 * 60,
  463. cdrom: root_path + "/images/experimental/os/FreeBSD-11.0-RELEASE-i386-bootonly.iso",
  464. expected_texts: ["Welcome to FreeBSD!"],
  465. actions: [
  466. {
  467. on_text: " Autoboot in ",
  468. run: "\n",
  469. }
  470. ],
  471. },
  472. {
  473. name: "Arch Linux",
  474. skip_if_disk_image_missing: true,
  475. timeout: 20 * 60,
  476. bzimage_initrd_from_filesystem: true,
  477. memory_size: 512 * 1024 * 1024,
  478. cmdline: [
  479. "rw apm=off vga=0x344 video=vesafb:ypan,vremap:8",
  480. "root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose mitigations=off",
  481. "audit=0 init=/usr/bin/init-openrc net.ifnames=0 biosdevname=0",
  482. ].join(" "),
  483. filesystem: {
  484. basefs: "images/fs.json",
  485. baseurl: "images/arch-nongz/",
  486. },
  487. expected_texts: [
  488. "root@localhost",
  489. "aaaaaaaaaaaaaaaaaaaa",
  490. "Hello, world",
  491. "Hello from JS",
  492. "Hello from OCaml",
  493. "Compress okay",
  494. "v86-in-v86 okay",
  495. ],
  496. actions: [
  497. {
  498. on_text: "root@localhost",
  499. run: `python -c 'print(100 * "a")'\n`,
  500. },
  501. {
  502. on_text: "aaaaaaaaaaaaaaaaaaaa",
  503. run: `gcc hello.c && ./a.out\n`,
  504. },
  505. {
  506. on_text: "Hello, world",
  507. run: `echo 'console.log("Hello from JS")' | node\n`,
  508. },
  509. {
  510. on_text: "Hello from JS",
  511. run: `echo 'print_endline "Hello from OCaml"' > hello.ml && ocamlopt hello.ml && ./a.out\n`,
  512. },
  513. {
  514. on_text: "Hello from OCaml",
  515. run:
  516. "zstd hello.c && gzip -k hello.c && bzip2 -k hello.c && xz -k hello.c && lzma -k hello.c && " +
  517. "zstdcat hello.c.zst && zcat hello.c.gz && bzcat hello.c.bz2 && xzcat hello.c.xz && lzmadec hello.c.lzma && " +
  518. "echo Compress okay\n",
  519. },
  520. {
  521. on_text: "Compress okay",
  522. run:
  523. RUN_SLOW_TESTS ?
  524. "./v86-in-v86.js | tee /dev/stderr | grep -m1 'Files send via emulator appear in' ; sleep 2; echo v86-in-v86 okay\n"
  525. :
  526. "./v86-in-v86.js | tee /dev/stderr | grep -m1 'Kernel command line:' ; sleep 2; echo v86-in-v86 okay\n",
  527. },
  528. {
  529. on_text: "v86-in-v86 okay",
  530. run: "./startx.sh\n",
  531. },
  532. ],
  533. expect_graphical_mode: true,
  534. expect_graphical_size: [1024, 768],
  535. expect_mouse_registered: true,
  536. },
  537. {
  538. name: "FreeGEM",
  539. skip_if_disk_image_missing: true,
  540. timeout: 60,
  541. hda: root_path + "/images/freegem.bin",
  542. expect_graphical_mode: true,
  543. expect_mouse_registered: true,
  544. actions: [
  545. {
  546. on_text: " Select from Menu",
  547. run: "3",
  548. }
  549. ],
  550. },
  551. {
  552. name: "Haiku",
  553. skip_if_disk_image_missing: true,
  554. timeout: 15 * 60,
  555. memory_size: 512 * 1024 * 1024,
  556. hda: root_path + "/images/haiku-r1beta2-hrev54154_111-x86_gcc2h-anyboot.iso",
  557. expected_serial_text: [
  558. "init_hardware()",
  559. "Running post install script /boot/system/boot/post-install/sshd_keymaker.sh",
  560. // After pressing enter in the boot dialog:
  561. "Running first login script /boot/system/boot/first-login/default_deskbar_items.sh",
  562. ],
  563. expect_graphical_mode: true,
  564. expect_graphical_size: [1024, 768],
  565. expect_mouse_registered: true,
  566. actions: [
  567. { after: 1 * 60 * 1000, run: "\n" },
  568. { after: 2 * 60 * 1000, run: "\n" },
  569. { after: 3 * 60 * 1000, run: "\n" },
  570. { after: 4 * 60 * 1000, run: "\n" },
  571. { after: 5 * 60 * 1000, run: "\n" },
  572. { after: 6 * 60 * 1000, run: "\n" },
  573. { after: 7 * 60 * 1000, run: "\n" },
  574. { after: 8 * 60 * 1000, run: "\n" },
  575. ],
  576. },
  577. {
  578. name: "9front",
  579. use_small_bios: true, // has issues with 256k bios
  580. skip_if_disk_image_missing: true,
  581. acpi: true,
  582. timeout: 5 * 60,
  583. hda: root_path + "/images/9front-7781.38dcaeaa222c.386.iso",
  584. expect_graphical_mode: true,
  585. expect_graphical_size: [1024, 768],
  586. expect_mouse_registered: true,
  587. actions: [
  588. { after: 60 * 1000, run: "\n" },
  589. { after: 70 * 1000, run: "\n" },
  590. { after: 80 * 1000, run: "\n" },
  591. { after: 90 * 1000, run: "\n" },
  592. { after: 100 * 1000, run: "\n" },
  593. { after: 110 * 1000, run: "\n" },
  594. { after: 120 * 1000, run: "\n" },
  595. { after: 130 * 1000, run: "\n" },
  596. { after: 140 * 1000, run: "\n" },
  597. { after: 150 * 1000, run: "\n" },
  598. { after: 160 * 1000, run: "\n" },
  599. { after: 170 * 1000, run: "\n" },
  600. { after: 180 * 1000, run: "\n" },
  601. ],
  602. },
  603. {
  604. name: "ReactOS",
  605. skip_if_disk_image_missing: true,
  606. timeout: 10 * 60,
  607. hda: root_path + "/images/reactos-livecd-0.4.15-dev-73-g03c09c9-x86-gcc-lin-dbg.iso",
  608. expect_graphical_mode: true,
  609. expect_graphical_size: [800, 600],
  610. expect_mouse_registered: true,
  611. actions: [
  612. { after: 1 * 60 * 1000, run: "\n" },
  613. { after: 2 * 60 * 1000, run: "\n" },
  614. { after: 3 * 60 * 1000, run: "\n" },
  615. { after: 4 * 60 * 1000, run: "\n" },
  616. { after: 5 * 60 * 1000, run: "\n" },
  617. { after: 6 * 60 * 1000, run: "\n" },
  618. { after: 7 * 60 * 1000, run: "\n" },
  619. { after: 8 * 60 * 1000, run: "\n" },
  620. ],
  621. expected_serial_text: [
  622. "DnsIntCacheInitialize()",
  623. // when desktop is rendered:
  624. "err: Attempted to close thread desktop",
  625. ],
  626. },
  627. {
  628. name: "ReactOS CD",
  629. skip_if_disk_image_missing: true,
  630. timeout: 10 * 60,
  631. cdrom: root_path + "/images/reactos-livecd-0.4.15-dev-73-g03c09c9-x86-gcc-lin-dbg.iso",
  632. expect_graphical_mode: true,
  633. expect_graphical_size: [800, 600],
  634. expect_mouse_registered: true,
  635. expected_serial_text: ["DnsIntCacheInitialize()"],
  636. },
  637. {
  638. name: "HelenOS",
  639. skip_if_disk_image_missing: true,
  640. timeout: 3 * 60,
  641. cdrom: root_path + "/images/HelenOS-0.11.2-ia32.iso",
  642. expect_graphical_mode: true,
  643. expect_mouse_registered: true,
  644. expected_serial_text: ["init: Spawning"],
  645. },
  646. {
  647. name: "Minix",
  648. skip_if_disk_image_missing: true,
  649. timeout: 60,
  650. hda: root_path + "/images/experimental/os/minix2hd.img",
  651. actions: [
  652. {
  653. on_text: " = Start Minix",
  654. run: "=",
  655. },
  656. {
  657. on_text: "noname login:",
  658. run: "root\n",
  659. },
  660. ],
  661. expected_texts: ["noname login:", "# "],
  662. },
  663. {
  664. name: "Minix CD",
  665. skip_if_disk_image_missing: true,
  666. timeout: 3 * 60,
  667. cdrom: root_path + "/images/minix-3.3.0.iso",
  668. actions: [
  669. {
  670. on_text: "login:",
  671. run: "root\n",
  672. },
  673. ],
  674. expected_texts: ["login:", "We'd like your feedback", "# "],
  675. },
  676. {
  677. name: "Mobius",
  678. skip_if_disk_image_missing: true,
  679. timeout: 2 * 60,
  680. fda: root_path + "/images/mobius-fd-release5.img",
  681. expect_graphical_mode: true,
  682. actions: [
  683. {
  684. on_text: " The highlighted entry will be booted automatically",
  685. run: "\n",
  686. },
  687. ],
  688. },
  689. {
  690. name: "FreeNOS",
  691. skip_if_disk_image_missing: true,
  692. timeout: 2 * 60,
  693. cdrom: root_path + "/images/FreeNOS-1.0.3.iso",
  694. acpi: true,
  695. actions: [
  696. {
  697. on_text: "login:",
  698. run: "root\n",
  699. },
  700. ],
  701. expected_texts: ["login:", "(localhost)"],
  702. expected_serial_text: ["FreeNOS 1.0.3"],
  703. },
  704. {
  705. name: "SerenityOS",
  706. skip_if_disk_image_missing: true,
  707. timeout: 2 * 60,
  708. hda: root_path + "/images/serenity.img",
  709. expect_graphical_mode: true,
  710. expect_graphical_size: [1024, 768],
  711. expect_mouse_registered: true,
  712. },
  713. {
  714. name: "Redox",
  715. skip_if_disk_image_missing: true,
  716. timeout: 5 * 60,
  717. memory_size: 512 * 1024 * 1024,
  718. acpi: true,
  719. hda: root_path + "/images/redox_demo_i686_2022-11-26_643_harddrive.img",
  720. actions: [
  721. { on_text: "Arrow keys and enter select mode", run: "\n" },
  722. ],
  723. expect_graphical_mode: true,
  724. expect_mouse_registered: true,
  725. expected_serial_text: ["# Login with the following:"],
  726. },
  727. {
  728. name: "Android 1.6",
  729. skip_if_disk_image_missing: true,
  730. timeout: 2 * 60,
  731. cdrom: root_path + "/images/android-x86-1.6-r2.iso",
  732. expect_graphical_mode: true,
  733. expect_graphical_size: [800, 600],
  734. expect_mouse_registered: true,
  735. },
  736. {
  737. name: "Android 4.4",
  738. skip_if_disk_image_missing: true,
  739. timeout: 5 * 60,
  740. hda: root_path + "/images/android_x86_nonsse3_4.4r1_20140904.iso",
  741. expect_graphical_mode: true,
  742. expect_graphical_size: [800, 600],
  743. expect_mouse_registered: true,
  744. },
  745. {
  746. name: "Syllable",
  747. skip_if_disk_image_missing: true,
  748. timeout: 60,
  749. memory_size: 512 * 1024 * 1024,
  750. hda: root_path + "/images/syllable-destop-0.6.7.img",
  751. expect_graphical_mode: true,
  752. expect_mouse_registered: true,
  753. },
  754. {
  755. name: "Linux with Postgres",
  756. skip_if_disk_image_missing: true,
  757. timeout: 5 * 60,
  758. memory_size: 512 * 1024 * 1024,
  759. cdrom: root_path + "/images/experimental/linux-postgres.iso",
  760. expected_texts: [
  761. "performing post-bootstrap initialization",
  762. "syncing data to disk",
  763. "Success. You can now start the database server using",
  764. ],
  765. },
  766. {
  767. name: "Tiny Core 11 CD",
  768. skip_if_disk_image_missing: 1,
  769. timeout: 10 * 60,
  770. cdrom: root_path + "/images/TinyCore-11.0.iso",
  771. expect_graphical_mode: true,
  772. expect_mouse_registered: true,
  773. actions: [{ on_text: " BIOS default device boot in", run: "\n", after: 5000 }],
  774. },
  775. {
  776. name: "Tiny Core 11 HD",
  777. skip_if_disk_image_missing: 1,
  778. timeout: 10 * 60,
  779. hda: root_path + "/images/TinyCore-11.0.iso",
  780. expect_graphical_mode: true,
  781. expect_mouse_registered: true,
  782. actions: [{ on_text: " BIOS default device boot in", run: "\n", after: 5000 }],
  783. },
  784. {
  785. name: "Core 9 (with floppy disk)",
  786. skip_if_disk_image_missing: 1,
  787. timeout: 5 * 60,
  788. cdrom: root_path + "/images/experimental/os/Core-9.0.iso",
  789. fda: root_path + "/images/freedos722.img",
  790. boot_order: 0x132,
  791. actions: [
  792. { on_text: "boot:", run: "\n" },
  793. { on_text: "tc@box", run: "sudo mount /dev/fd0 /mnt && ls /mnt\n" },
  794. ],
  795. expected_texts: ["AUTOEXEC.BAT"],
  796. },
  797. {
  798. name: "Core 8",
  799. skip_if_disk_image_missing: 1,
  800. timeout: 5 * 60,
  801. cdrom: root_path + "/images/experimental/os/Core-8.0.iso",
  802. expected_texts: ["tc@box"],
  803. actions: [{ on_text: "boot:", run: "\n" }],
  804. },
  805. {
  806. name: "Core 7",
  807. skip_if_disk_image_missing: 1,
  808. timeout: 5 * 60,
  809. cdrom: root_path + "/images/experimental/os/Core-7.2.iso",
  810. expected_texts: ["tc@box"],
  811. actions: [{ on_text: "boot:", run: "\n" }],
  812. },
  813. {
  814. name: "Core 6",
  815. skip_if_disk_image_missing: 1,
  816. timeout: 5 * 60,
  817. cdrom: root_path + "/images/experimental/os/Core-6.4.1.iso",
  818. expected_texts: ["tc@box"],
  819. actions: [{ on_text: "boot:", run: "\n" }],
  820. },
  821. {
  822. name: "Core 5",
  823. skip_if_disk_image_missing: 1,
  824. timeout: 5 * 60,
  825. cdrom: root_path + "/images/experimental/os/Core-5.4.iso",
  826. expected_texts: ["tc@box"],
  827. actions: [{ on_text: "boot:", run: "\n" }],
  828. },
  829. {
  830. name: "Core 4",
  831. skip_if_disk_image_missing: 1,
  832. timeout: 5 * 60,
  833. cdrom: root_path + "/images/experimental/os/Core-4.7.7.iso",
  834. expected_texts: ["tc@box"],
  835. actions: [{ on_text: "boot:", run: "\n" }],
  836. },
  837. {
  838. name: "Damn Small Linux",
  839. skip_if_disk_image_missing: 1,
  840. timeout: 5 * 60,
  841. cdrom: root_path + "/images/dsl-4.11.rc2.iso",
  842. expect_graphical_mode: true,
  843. expect_graphical_size: [1024, 768],
  844. expect_mouse_registered: true,
  845. },
  846. ];
  847. if(TEST_NAME)
  848. {
  849. tests = tests.filter(test => test.name === TEST_NAME);
  850. }
  851. var nr_of_cpus = Math.min(Math.round(os.cpus().length / 2) || 1, tests.length, MAX_PARALLEL_TESTS);
  852. console.log("Using %d cpus", nr_of_cpus);
  853. var current_test = 0;
  854. for(var i = 0; i < nr_of_cpus; i++)
  855. {
  856. var worker = cluster.fork();
  857. worker.on("message", send_work_to_worker.bind(null, worker));
  858. worker.on("online", send_work_to_worker.bind(null, worker));
  859. worker.on("exit", function(code, signal)
  860. {
  861. if(signal)
  862. {
  863. console.warn("Worker killed by signal " + signal);
  864. process.exit(1);
  865. }
  866. else if(code !== 0)
  867. {
  868. process.exit(code);
  869. }
  870. });
  871. worker.on("error", function(error)
  872. {
  873. console.error("Worker error: ", error.toString(), error);
  874. process.exit(1);
  875. });
  876. }
  877. }
  878. else
  879. {
  880. cluster.worker.on("message", function(test_case)
  881. {
  882. run_test(test_case, function()
  883. {
  884. process.send("I'm done");
  885. });
  886. });
  887. }
  888. function bytearray_starts_with(arr, search)
  889. {
  890. for(var i = 0; i < search.length; i++)
  891. {
  892. if(arr[i] !== search[i])
  893. {
  894. return false;
  895. }
  896. }
  897. return true;
  898. }
  899. function run_test(test, done)
  900. {
  901. console.log("Starting test: %s", test.name);
  902. const images = [test.fda, test.hda, test.cdrom, test.bzimage, test.filesystem && test.filesystem.basefs].filter(x => x);
  903. assert(images.length, "Bootable drive expected");
  904. const missing_images = images.filter(i => !fs.existsSync(i));
  905. if(missing_images.length)
  906. {
  907. if(test.skip_if_disk_image_missing)
  908. {
  909. console.warn("Missing disk image: " + missing_images.join(", ") + ", test skipped");
  910. console.warn();
  911. done();
  912. return;
  913. }
  914. else
  915. {
  916. console.warn("Missing disk image: " + missing_images.join(", "));
  917. process.exit(1);
  918. }
  919. }
  920. if(test.slow && !RUN_SLOW_TESTS)
  921. {
  922. console.warn("Slow test: " + test.name + ", skipped");
  923. console.warn();
  924. done();
  925. return;
  926. }
  927. if(test.alternative_bios)
  928. {
  929. var bios = root_path + "/bios/bochs-bios.bin";
  930. var vga_bios = root_path + "/bios/bochs-vgabios.bin";
  931. }
  932. else if(test.use_small_bios || TEST_RELEASE_BUILD)
  933. {
  934. var bios = root_path + "/bios/seabios.bin";
  935. var vga_bios = root_path + "/bios/vgabios.bin";
  936. }
  937. else
  938. {
  939. var bios = root_path + "/bios/seabios-debug.bin";
  940. var vga_bios = root_path + "/bios/vgabios-debug.bin";
  941. }
  942. var settings = {
  943. bios: { url: bios },
  944. vga_bios: { url: vga_bios },
  945. autostart: true,
  946. memory_size: test.memory_size || 128 * 1024 * 1024,
  947. log_level: 0,
  948. cmdline: test.cmdline,
  949. };
  950. if(test.cdrom)
  951. {
  952. settings.cdrom = { url: test.cdrom };
  953. }
  954. if(test.fda)
  955. {
  956. settings.fda = { url: test.fda };
  957. }
  958. if(test.hda)
  959. {
  960. settings.hda = { url: test.hda, async: true };
  961. }
  962. if(test.bzimage)
  963. {
  964. settings.bzimage = { url: test.bzimage };
  965. }
  966. if(test.filesystem)
  967. {
  968. settings.filesystem = test.filesystem;
  969. }
  970. settings.cmdline = test.cmdline;
  971. settings.bzimage_initrd_from_filesystem = test.bzimage_initrd_from_filesystem;
  972. settings.acpi = test.acpi;
  973. settings.boot_order = test.boot_order;
  974. settings.cpuid_level = test.cpuid_level;
  975. settings.disable_jit = +process.env.DISABLE_JIT;
  976. if(test.expected_texts)
  977. {
  978. test.expected_texts = test.expected_texts.map(string_to_bytearray);
  979. }
  980. else
  981. {
  982. test.expected_texts = [];
  983. }
  984. if(!test.expected_serial_text)
  985. {
  986. test.expected_serial_text = [];
  987. }
  988. var emulator = new V86(settings);
  989. var screen = new Uint8Array(SCREEN_WIDTH * 25);
  990. function check_text_test_done()
  991. {
  992. return test.expected_texts.length === 0;
  993. }
  994. function check_serial_test_done()
  995. {
  996. return test.expected_serial_text.length === 0;
  997. }
  998. var mouse_test_done = false;
  999. function check_mouse_test_done()
  1000. {
  1001. return !test.expect_mouse_registered || mouse_test_done;
  1002. }
  1003. var graphical_test_done = false;
  1004. var size_test_done = false;
  1005. function check_graphical_test_done()
  1006. {
  1007. return !test.expect_graphical_mode || (graphical_test_done && (!test.expect_graphical_size || size_test_done));
  1008. }
  1009. var test_start = Date.now();
  1010. var timeout_seconds = test.timeout * TIMEOUT_EXTRA_FACTOR;
  1011. var timeout = setTimeout(check_test_done, (timeout_seconds + 1) * 1000);
  1012. var timeouts = [timeout];
  1013. var on_text = [];
  1014. var stopped = false;
  1015. var screen_interval = null;
  1016. function check_test_done()
  1017. {
  1018. if(stopped)
  1019. {
  1020. return;
  1021. }
  1022. if(check_text_test_done() &&
  1023. check_mouse_test_done() &&
  1024. check_graphical_test_done() &&
  1025. check_serial_test_done())
  1026. {
  1027. var end = Date.now();
  1028. for(let timeout of timeouts) clearTimeout(timeout);
  1029. stopped = true;
  1030. emulator.stop();
  1031. if(screen_interval !== null)
  1032. {
  1033. clearInterval(screen_interval);
  1034. }
  1035. console.warn("Passed test: %s (took %ds)", test.name, (end - test_start) / 1000);
  1036. console.warn();
  1037. done();
  1038. }
  1039. else if(Date.now() >= test_start + timeout_seconds * 1000)
  1040. {
  1041. for(let timeout of timeouts) clearTimeout(timeout);
  1042. stopped = true;
  1043. if(screen_interval !== null)
  1044. {
  1045. clearInterval(screen_interval);
  1046. }
  1047. emulator.stop();
  1048. emulator.destroy();
  1049. if(test.failure_allowed)
  1050. {
  1051. console.warn("Test failed: %s (failure allowed)\n", test.name);
  1052. }
  1053. else
  1054. {
  1055. console.warn(screen_to_text(screen));
  1056. console.warn("Test failed: %s\n", test.name);
  1057. }
  1058. if(!check_text_test_done())
  1059. {
  1060. console.warn('Expected text "%s" after %d seconds.', bytearray_to_string(test.expected_texts[0]), timeout_seconds);
  1061. }
  1062. if(!check_graphical_test_done())
  1063. {
  1064. console.warn("Expected graphical mode after %d seconds.", timeout_seconds);
  1065. }
  1066. if(!check_mouse_test_done())
  1067. {
  1068. console.warn("Expected mouse activation after %d seconds.", timeout_seconds);
  1069. }
  1070. if(!check_serial_test_done())
  1071. {
  1072. console.warn('Expected serial text "%s" after %d seconds.', test.expected_serial_text, timeout_seconds);
  1073. }
  1074. if(on_text.length)
  1075. {
  1076. console.warn(`Note: Expected text "${bytearray_to_string(on_text[0].text)}" to run "${on_text[0].run}"`);
  1077. }
  1078. if(!test.failure_allowed)
  1079. {
  1080. process.exit(1);
  1081. }
  1082. else
  1083. {
  1084. done();
  1085. }
  1086. }
  1087. }
  1088. emulator.add_listener("mouse-enable", function()
  1089. {
  1090. mouse_test_done = true;
  1091. check_test_done();
  1092. });
  1093. emulator.add_listener("screen-set-mode", function(is_graphical)
  1094. {
  1095. graphical_test_done = is_graphical;
  1096. check_test_done();
  1097. });
  1098. emulator.add_listener("screen-set-size-graphical", function(size)
  1099. {
  1100. if(test.expect_graphical_size)
  1101. {
  1102. size_test_done = size[0] === test.expect_graphical_size[0] &&
  1103. size[1] === test.expect_graphical_size[1];
  1104. check_test_done();
  1105. }
  1106. });
  1107. emulator.add_listener("screen-put-char", function(chr)
  1108. {
  1109. var y = chr[0];
  1110. var x = chr[1];
  1111. var code = chr[2];
  1112. screen[x + SCREEN_WIDTH * y] = code;
  1113. var line = get_line(screen, y);
  1114. if(!check_text_test_done())
  1115. {
  1116. let expected = test.expected_texts[0];
  1117. if(x < expected.length && bytearray_starts_with(line, expected))
  1118. {
  1119. test.expected_texts.shift();
  1120. if(VERBOSE) console.log(`Passed: "${bytearray_to_string(expected)}" on screen (${test.name})`);
  1121. check_test_done();
  1122. }
  1123. }
  1124. if(on_text.length)
  1125. {
  1126. let expected = on_text[0].text;
  1127. if(x < expected.length && bytearray_starts_with(line, expected))
  1128. {
  1129. var action = on_text.shift();
  1130. timeouts.push(
  1131. setTimeout(() => {
  1132. if(VERBOSE) console.error("Sending '%s'", action.run);
  1133. emulator.keyboard_send_text(action.run);
  1134. }, action.after || 0)
  1135. );
  1136. }
  1137. }
  1138. });
  1139. if(LOG_SCREEN)
  1140. {
  1141. screen_interval = setInterval(() => {
  1142. console.warn(screen_to_text(screen));
  1143. }, 10000);
  1144. }
  1145. let serial_line = "";
  1146. emulator.add_listener("serial0-output-byte", function(byte)
  1147. {
  1148. var c = String.fromCharCode(byte);
  1149. if(c === "\n")
  1150. {
  1151. if(VERBOSE)
  1152. {
  1153. console.log(`Serial (${test.name}):`, serial_line);
  1154. }
  1155. if(test.expected_serial_text.length)
  1156. {
  1157. const expected = test.expected_serial_text[0];
  1158. if(serial_line.includes(expected))
  1159. {
  1160. test.expected_serial_text.shift();
  1161. if(VERBOSE) console.log(`Passed: "${expected}" on serial (${test.name})`);
  1162. check_test_done();
  1163. }
  1164. }
  1165. serial_line = "";
  1166. }
  1167. else if(c >= " " && c <= "~")
  1168. {
  1169. serial_line += c;
  1170. }
  1171. });
  1172. test.actions && test.actions.forEach(function(action)
  1173. {
  1174. if(action.on_text)
  1175. {
  1176. on_text.push({ text: string_to_bytearray(action.on_text), run: action.run, after: action.after });
  1177. }
  1178. else
  1179. {
  1180. timeouts.push(
  1181. setTimeout(() => {
  1182. if(VERBOSE) console.error("Sending '%s'", action.run);
  1183. emulator.keyboard_send_text(action.run);
  1184. }, action.after || 0)
  1185. );
  1186. }
  1187. });
  1188. }