1
0

run.js 41 KB

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