run.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  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/internal/freebsd/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. failure_allowed: true,
  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: 2 * 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: "Linux with Postgres",
  747. skip_if_disk_image_missing: true,
  748. timeout: 5 * 60,
  749. memory_size: 512 * 1024 * 1024,
  750. cdrom: root_path + "/images/experimental/linux-postgres.iso",
  751. expected_texts: [
  752. "performing post-bootstrap initialization",
  753. "syncing data to disk",
  754. "Success. You can now start the database server using",
  755. ],
  756. },
  757. {
  758. name: "Tiny Core 11 CD",
  759. skip_if_disk_image_missing: 1,
  760. timeout: 10 * 60,
  761. cdrom: root_path + "/images/TinyCore-11.0.iso",
  762. expect_graphical_mode: true,
  763. expect_mouse_registered: true,
  764. actions: [{ on_text: " BIOS default device boot in", run: "\n", after: 5000 }],
  765. },
  766. {
  767. name: "Tiny Core 11 HD",
  768. skip_if_disk_image_missing: 1,
  769. timeout: 10 * 60,
  770. hda: 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: "Core 9 (with floppy disk)",
  777. skip_if_disk_image_missing: 1,
  778. timeout: 5 * 60,
  779. cdrom: root_path + "/images/experimental/os/Core-9.0.iso",
  780. fda: root_path + "/images/freedos722.img",
  781. boot_order: 0x132,
  782. actions: [
  783. { on_text: "boot:", run: "\n" },
  784. { on_text: "tc@box", run: "sudo mount /dev/fd0 /mnt && ls /mnt\n" },
  785. ],
  786. expected_texts: ["AUTOEXEC.BAT"],
  787. },
  788. {
  789. name: "Core 8",
  790. skip_if_disk_image_missing: 1,
  791. timeout: 5 * 60,
  792. cdrom: root_path + "/images/experimental/os/Core-8.0.iso",
  793. expected_texts: ["tc@box"],
  794. actions: [{ on_text: "boot:", run: "\n" }],
  795. },
  796. {
  797. name: "Core 7",
  798. skip_if_disk_image_missing: 1,
  799. timeout: 5 * 60,
  800. cdrom: root_path + "/images/experimental/os/Core-7.2.iso",
  801. expected_texts: ["tc@box"],
  802. actions: [{ on_text: "boot:", run: "\n" }],
  803. },
  804. {
  805. name: "Core 6",
  806. skip_if_disk_image_missing: 1,
  807. timeout: 5 * 60,
  808. cdrom: root_path + "/images/experimental/os/Core-6.4.1.iso",
  809. expected_texts: ["tc@box"],
  810. actions: [{ on_text: "boot:", run: "\n" }],
  811. },
  812. {
  813. name: "Core 5",
  814. skip_if_disk_image_missing: 1,
  815. timeout: 5 * 60,
  816. cdrom: root_path + "/images/experimental/os/Core-5.4.iso",
  817. expected_texts: ["tc@box"],
  818. actions: [{ on_text: "boot:", run: "\n" }],
  819. },
  820. {
  821. name: "Core 4",
  822. skip_if_disk_image_missing: 1,
  823. timeout: 5 * 60,
  824. cdrom: root_path + "/images/experimental/os/Core-4.7.7.iso",
  825. expected_texts: ["tc@box"],
  826. actions: [{ on_text: "boot:", run: "\n" }],
  827. },
  828. {
  829. name: "Damn Small Linux",
  830. skip_if_disk_image_missing: 1,
  831. timeout: 5 * 60,
  832. cdrom: root_path + "/images/dsl-4.11.rc2.iso",
  833. expect_graphical_mode: true,
  834. expect_graphical_size: [1024, 768],
  835. expect_mouse_registered: true,
  836. },
  837. ];
  838. if(TEST_NAME)
  839. {
  840. tests = tests.filter(test => test.name === TEST_NAME);
  841. }
  842. var nr_of_cpus = Math.min(Math.round(os.cpus().length / 2) || 1, tests.length, MAX_PARALLEL_TESTS);
  843. console.log("Using %d cpus", nr_of_cpus);
  844. var current_test = 0;
  845. for(var i = 0; i < nr_of_cpus; i++)
  846. {
  847. var worker = cluster.fork();
  848. worker.on("message", send_work_to_worker.bind(null, worker));
  849. worker.on("online", send_work_to_worker.bind(null, worker));
  850. worker.on("exit", function(code, signal)
  851. {
  852. if(signal)
  853. {
  854. console.warn("Worker killed by signal " + signal);
  855. process.exit(1);
  856. }
  857. else if(code !== 0)
  858. {
  859. process.exit(code);
  860. }
  861. });
  862. worker.on("error", function(error)
  863. {
  864. console.error("Worker error: ", error.toString(), error);
  865. process.exit(1);
  866. });
  867. }
  868. }
  869. else
  870. {
  871. cluster.worker.on("message", function(test_case)
  872. {
  873. run_test(test_case, function()
  874. {
  875. process.send("I'm done");
  876. });
  877. });
  878. }
  879. function bytearray_starts_with(arr, search)
  880. {
  881. for(var i = 0; i < search.length; i++)
  882. {
  883. if(arr[i] !== search[i])
  884. {
  885. return false;
  886. }
  887. }
  888. return true;
  889. }
  890. function run_test(test, done)
  891. {
  892. console.log("Starting test: %s", test.name);
  893. const images = [test.fda, test.hda, test.cdrom, test.bzimage, test.filesystem && test.filesystem.basefs].filter(x => x);
  894. assert(images.length, "Bootable drive expected");
  895. const missing_images = images.filter(i => !fs.existsSync(i));
  896. if(missing_images.length)
  897. {
  898. if(test.skip_if_disk_image_missing)
  899. {
  900. console.warn("Missing disk image: " + missing_images.join(", ") + ", test skipped");
  901. console.warn();
  902. done();
  903. return;
  904. }
  905. else
  906. {
  907. console.warn("Missing disk image: " + missing_images.join(", "));
  908. process.exit(1);
  909. }
  910. }
  911. if(test.slow && !RUN_SLOW_TESTS)
  912. {
  913. console.warn("Slow test: " + test.name + ", skipped");
  914. console.warn();
  915. done();
  916. return;
  917. }
  918. if(test.alternative_bios)
  919. {
  920. var bios = root_path + "/bios/bochs-bios.bin";
  921. var vga_bios = root_path + "/bios/bochs-vgabios.bin";
  922. }
  923. else if(TEST_RELEASE_BUILD)
  924. {
  925. var bios = root_path + "/bios/seabios.bin";
  926. var vga_bios = root_path + "/bios/vgabios.bin";
  927. }
  928. else
  929. {
  930. var bios = root_path + "/bios/seabios-debug.bin";
  931. var vga_bios = root_path + "/bios/vgabios-debug.bin";
  932. }
  933. var settings = {
  934. bios: { url: bios },
  935. vga_bios: { url: vga_bios },
  936. autostart: true,
  937. memory_size: test.memory_size || 128 * 1024 * 1024,
  938. log_level: 0,
  939. cmdline: test.cmdline,
  940. };
  941. if(test.cdrom)
  942. {
  943. settings.cdrom = { url: test.cdrom };
  944. }
  945. if(test.fda)
  946. {
  947. settings.fda = { url: test.fda };
  948. }
  949. if(test.hda)
  950. {
  951. settings.hda = { url: test.hda, async: true };
  952. }
  953. if(test.bzimage)
  954. {
  955. settings.bzimage = { url: test.bzimage };
  956. }
  957. if(test.filesystem)
  958. {
  959. settings.filesystem = test.filesystem;
  960. }
  961. settings.cmdline = test.cmdline;
  962. settings.bzimage_initrd_from_filesystem = test.bzimage_initrd_from_filesystem;
  963. settings.acpi = test.acpi;
  964. settings.boot_order = test.boot_order;
  965. settings.cpuid_level = test.cpuid_level;
  966. if(test.expected_texts)
  967. {
  968. test.expected_texts = test.expected_texts.map(string_to_bytearray);
  969. }
  970. else
  971. {
  972. test.expected_texts = [];
  973. }
  974. if(!test.expected_serial_text)
  975. {
  976. test.expected_serial_text = [];
  977. }
  978. var emulator = new V86(settings);
  979. var screen = new Uint8Array(SCREEN_WIDTH * 25);
  980. function check_text_test_done()
  981. {
  982. return test.expected_texts.length === 0;
  983. }
  984. function check_serial_test_done()
  985. {
  986. return test.expected_serial_text.length === 0;
  987. }
  988. var mouse_test_done = false;
  989. function check_mouse_test_done()
  990. {
  991. return !test.expect_mouse_registered || mouse_test_done;
  992. }
  993. var graphical_test_done = false;
  994. var size_test_done = false;
  995. function check_graphical_test_done()
  996. {
  997. return !test.expect_graphical_mode || (graphical_test_done && (!test.expect_graphical_size || size_test_done));
  998. }
  999. var test_start = Date.now();
  1000. var timeout_seconds = test.timeout * TIMEOUT_EXTRA_FACTOR;
  1001. var timeout = setTimeout(check_test_done, (timeout_seconds + 1) * 1000);
  1002. var timeouts = [timeout];
  1003. var on_text = [];
  1004. var stopped = false;
  1005. var screen_interval = null;
  1006. function check_test_done()
  1007. {
  1008. if(stopped)
  1009. {
  1010. return;
  1011. }
  1012. if(check_text_test_done() &&
  1013. check_mouse_test_done() &&
  1014. check_graphical_test_done() &&
  1015. check_serial_test_done())
  1016. {
  1017. var end = Date.now();
  1018. for(let timeout of timeouts) clearTimeout(timeout);
  1019. stopped = true;
  1020. emulator.stop();
  1021. if(screen_interval !== null)
  1022. {
  1023. clearInterval(screen_interval);
  1024. }
  1025. console.warn("Passed test: %s (took %ds)", test.name, (end - test_start) / 1000);
  1026. console.warn();
  1027. done();
  1028. }
  1029. else if(Date.now() >= test_start + timeout_seconds * 1000)
  1030. {
  1031. for(let timeout of timeouts) clearTimeout(timeout);
  1032. stopped = true;
  1033. if(screen_interval !== null)
  1034. {
  1035. clearInterval(screen_interval);
  1036. }
  1037. emulator.stop();
  1038. emulator.destroy();
  1039. if(test.failure_allowed)
  1040. {
  1041. console.warn("Test failed: %s (failure allowed)\n", test.name);
  1042. }
  1043. else
  1044. {
  1045. console.warn(screen_to_text(screen));
  1046. console.warn("Test failed: %s\n", test.name);
  1047. }
  1048. if(!check_text_test_done())
  1049. {
  1050. console.warn('Expected text "%s" after %d seconds.', bytearray_to_string(test.expected_texts[0]), timeout_seconds);
  1051. }
  1052. if(!check_graphical_test_done())
  1053. {
  1054. console.warn("Expected graphical mode after %d seconds.", timeout_seconds);
  1055. }
  1056. if(!check_mouse_test_done())
  1057. {
  1058. console.warn("Expected mouse activation after %d seconds.", timeout_seconds);
  1059. }
  1060. if(!check_serial_test_done())
  1061. {
  1062. console.warn('Expected serial text "%s" after %d seconds.', test.expected_serial_text, timeout_seconds);
  1063. }
  1064. if(on_text.length)
  1065. {
  1066. console.warn(`Note: Expected text "${bytearray_to_string(on_text[0].text)}" to run "${on_text[0].run}"`);
  1067. }
  1068. if(!test.failure_allowed)
  1069. {
  1070. process.exit(1);
  1071. }
  1072. else
  1073. {
  1074. done();
  1075. }
  1076. }
  1077. }
  1078. emulator.add_listener("mouse-enable", function()
  1079. {
  1080. mouse_test_done = true;
  1081. check_test_done();
  1082. });
  1083. emulator.add_listener("screen-set-mode", function(is_graphical)
  1084. {
  1085. graphical_test_done = is_graphical;
  1086. check_test_done();
  1087. });
  1088. emulator.add_listener("screen-set-size-graphical", function(size)
  1089. {
  1090. if(test.expect_graphical_size)
  1091. {
  1092. size_test_done = size[0] === test.expect_graphical_size[0] &&
  1093. size[1] === test.expect_graphical_size[1];
  1094. check_test_done();
  1095. }
  1096. });
  1097. emulator.add_listener("screen-put-char", function(chr)
  1098. {
  1099. var y = chr[0];
  1100. var x = chr[1];
  1101. var code = chr[2];
  1102. screen[x + SCREEN_WIDTH * y] = code;
  1103. var line = get_line(screen, y);
  1104. if(!check_text_test_done())
  1105. {
  1106. let expected = test.expected_texts[0];
  1107. if(x < expected.length && bytearray_starts_with(line, expected))
  1108. {
  1109. test.expected_texts.shift();
  1110. if(VERBOSE) console.log(`Passed: "${bytearray_to_string(expected)}" on screen (${test.name})`);
  1111. check_test_done();
  1112. }
  1113. }
  1114. if(on_text.length)
  1115. {
  1116. let expected = on_text[0].text;
  1117. if(x < expected.length && bytearray_starts_with(line, expected))
  1118. {
  1119. var action = on_text.shift();
  1120. timeouts.push(
  1121. setTimeout(() => {
  1122. if(VERBOSE) console.error("Sending '%s'", action.run);
  1123. emulator.keyboard_send_text(action.run);
  1124. }, action.after || 0)
  1125. );
  1126. }
  1127. }
  1128. });
  1129. if(LOG_SCREEN)
  1130. {
  1131. screen_interval = setInterval(() => {
  1132. console.warn(screen_to_text(screen));
  1133. }, 10000);
  1134. }
  1135. let serial_line = "";
  1136. emulator.add_listener("serial0-output-byte", function(byte)
  1137. {
  1138. var c = String.fromCharCode(byte);
  1139. if(c === "\n")
  1140. {
  1141. if(VERBOSE)
  1142. {
  1143. console.log(`Serial (${test.name}):`, serial_line);
  1144. }
  1145. if(test.expected_serial_text.length)
  1146. {
  1147. const expected = test.expected_serial_text[0];
  1148. if(serial_line.includes(expected))
  1149. {
  1150. test.expected_serial_text.shift();
  1151. if(VERBOSE) console.log(`Passed: "${expected}" on serial (${test.name})`);
  1152. check_test_done();
  1153. }
  1154. }
  1155. serial_line = "";
  1156. }
  1157. else if(c >= " " && c <= "~")
  1158. {
  1159. serial_line += c;
  1160. }
  1161. });
  1162. test.actions && test.actions.forEach(function(action)
  1163. {
  1164. if(action.on_text)
  1165. {
  1166. on_text.push({ text: string_to_bytearray(action.on_text), run: action.run, after: action.after });
  1167. }
  1168. else
  1169. {
  1170. timeouts.push(
  1171. setTimeout(() => {
  1172. if(VERBOSE) console.error("Sending '%s'", action.run);
  1173. emulator.keyboard_send_text(action.run);
  1174. }, action.after || 0)
  1175. );
  1176. }
  1177. });
  1178. }