run.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  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 VERBOSE = false;
  9. const RUN_SLOW_TESTS = 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);
  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 2000",
  137. skip_if_disk_image_missing: true,
  138. hda: root_path + "/images/windows2k.img",
  139. memory_size: 512 * 1024 * 1024,
  140. timeout: 300,
  141. expect_graphical_mode: true,
  142. expect_graphical_size: [1024, 768],
  143. expect_mouse_registered: true,
  144. },
  145. //{
  146. // name: "Windows 98",
  147. // skip_if_disk_image_missing: true,
  148. // hda: root_path + "/images/windows98.img",
  149. // timeout: 60,
  150. // expect_graphical_mode: true,
  151. // expect_graphical_size: [800, 600],
  152. // expect_mouse_registered: true,
  153. // failure_allowed: true,
  154. //},
  155. {
  156. name: "Windows 95",
  157. skip_if_disk_image_missing: true,
  158. hda: root_path + "/images/w95.img",
  159. timeout: 60,
  160. expect_graphical_mode: true,
  161. expect_graphical_size: [1024, 768],
  162. expect_mouse_registered: true,
  163. failure_allowed: true,
  164. },
  165. {
  166. name: "Oberon",
  167. skip_if_disk_image_missing: true,
  168. hda: root_path + "/images/oberon.img",
  169. timeout: 30,
  170. expect_graphical_mode: true,
  171. expect_mouse_registered: true,
  172. },
  173. {
  174. name: "Linux 3",
  175. skip_if_disk_image_missing: true,
  176. cdrom: root_path + "/images/linux3.iso",
  177. timeout: 200,
  178. expected_texts: [
  179. "test passed",
  180. ],
  181. actions: [
  182. {
  183. on_text: "~%",
  184. run: "head -c 10000 /dev/urandom > rand; echo test pas''sed\n",
  185. after: 1000,
  186. },
  187. ],
  188. },
  189. {
  190. name: "Linux 3 reboot",
  191. cdrom: root_path + "/images/linux3.iso",
  192. timeout: 90,
  193. expected_texts: [
  194. "~%",
  195. "SeaBIOS ",
  196. "~%",
  197. ],
  198. actions: [
  199. {
  200. on_text: "~%",
  201. run: "reboot\n",
  202. },
  203. ],
  204. },
  205. {
  206. name: "KolibriOS",
  207. fda: root_path + "/images/kolibri.img",
  208. timeout: 120,
  209. expect_graphical_mode: true,
  210. expect_mouse_registered: true,
  211. },
  212. {
  213. name: "Linux with Bochs BIOS",
  214. cdrom: root_path + "/images/linux.iso",
  215. timeout: 90,
  216. expected_texts: [
  217. "/root%",
  218. "test passed",
  219. ],
  220. alternative_bios: true,
  221. actions: [
  222. {
  223. on_text: "/root%",
  224. run: "cd tests; ./test-i386 > emu.test; diff emu.test reference.test && echo test pas''sed || echo failed\n",
  225. },
  226. ],
  227. },
  228. {
  229. name: "MS-DOS",
  230. skip_if_disk_image_missing: true,
  231. hda: root_path + "/images/msdos.img",
  232. timeout: 90,
  233. expected_texts: [
  234. "C:\\>",
  235. ],
  236. },
  237. {
  238. name: "Linux 4",
  239. skip_if_disk_image_missing: true,
  240. cdrom: root_path + "/images/linux4.iso",
  241. timeout: 200,
  242. expected_texts: [
  243. "~%",
  244. ],
  245. expected_serial_text: [
  246. "Files send via emulator appear in",
  247. ],
  248. expect_mouse_registered: true,
  249. },
  250. {
  251. name: "Linux bzImage",
  252. bzimage: root_path + "/images/buildroot-bzimage.bin",
  253. cmdline: "auto",
  254. timeout: 200,
  255. expected_texts: [
  256. "~%",
  257. ],
  258. expected_serial_text: [
  259. "Files send via emulator appear in",
  260. ],
  261. expect_mouse_registered: true,
  262. },
  263. {
  264. name: "Linux with bzImage from filesystem",
  265. bzimage_initrd_from_filesystem: true,
  266. filesystem: {
  267. basefs: root_path + "/build/integration-test-fs/fs.json",
  268. baseurl: root_path + "/build/integration-test-fs/flat/",
  269. },
  270. cmdline: "auto",
  271. timeout: 200,
  272. expected_texts: [
  273. "~%",
  274. ],
  275. expected_serial_text: [
  276. "Files send via emulator appear in",
  277. ],
  278. expect_mouse_registered: true,
  279. },
  280. {
  281. name: "QNX",
  282. skip_if_disk_image_missing: true,
  283. fda: root_path + "/images/qnx-demo-network-4.05.img",
  284. timeout: 300,
  285. expect_mouse_registered: true,
  286. expect_graphical_mode: true,
  287. expect_graphical_size: [640, 480],
  288. actions: [
  289. { run: " ", after: 30 * 1000 },
  290. { run: " ", after: 15 * 1000 },
  291. { run: " ", after: 15 * 1000 },
  292. { run: " ", after: 15 * 1000 },
  293. { run: " ", after: 15 * 1000 },
  294. { run: " ", after: 15 * 1000 },
  295. { run: " ", after: 15 * 1000 },
  296. ],
  297. },
  298. {
  299. name: "OpenBSD Floppy",
  300. fda: root_path + "/images/openbsd-floppy.img",
  301. timeout: 180,
  302. expected_texts: ["(I)nstall, (U)pgrade or (S)hell"],
  303. },
  304. {
  305. name: "OpenBSD",
  306. skip_if_disk_image_missing: true,
  307. hda: root_path + "/images/openbsd.img",
  308. timeout: 300,
  309. actions: [
  310. {
  311. on_text: "boot>",
  312. run: "boot -c\n",
  313. },
  314. {
  315. on_text: "UKC>",
  316. run: "disable mpbios\nexit\n",
  317. },
  318. {
  319. on_text: "login:",
  320. run: "root\n",
  321. },
  322. {
  323. on_text: "Password:",
  324. run: "root\n",
  325. },
  326. ],
  327. expected_texts: ["nyu# "],
  328. },
  329. {
  330. name: "Windows 3.0",
  331. slow: 1,
  332. skip_if_disk_image_missing: true,
  333. timeout: 10 * 60,
  334. cdrom: root_path + "/images/Win30.iso",
  335. expected_texts: [
  336. "Press any key to continue",
  337. " **************************************************",
  338. ],
  339. expect_graphical_mode: true,
  340. expect_mouse_registered: true,
  341. actions: [
  342. {
  343. on_text: "Press any key to continue . . .",
  344. after: 1000,
  345. run: "x",
  346. },
  347. {
  348. on_text: " **************************************************",
  349. after: 1000,
  350. run: "x",
  351. },
  352. {
  353. on_text: "C> ",
  354. after: 1000,
  355. run: "win\n",
  356. },
  357. ],
  358. },
  359. {
  360. name: "Windows 3.1",
  361. skip_if_disk_image_missing: true,
  362. timeout: 2 * 60,
  363. hda: root_path + "/images/win31.img",
  364. expect_graphical_mode: true,
  365. expect_graphical_size: [1024, 768],
  366. expect_mouse_registered: true,
  367. expected_texts: [
  368. "MODE prepare code page function completed",
  369. ],
  370. },
  371. {
  372. name: "FreeBSD",
  373. skip_if_disk_image_missing: true,
  374. timeout: 15 * 60,
  375. hda: root_path + "/images/internal/freebsd/freebsd.img",
  376. expected_texts: [
  377. "FreeBSD/i386 (nyu) (ttyv0)",
  378. "root@nyu:~ #",
  379. ],
  380. actions: [
  381. {
  382. on_text: " Autoboot in",
  383. run: "\n",
  384. },
  385. {
  386. // workaround for freebsd not accepting key inputs just before the boot prompt
  387. // (probably needs delay between keydown and keyup)
  388. on_text: "FreeBSD/i386 (nyu) (ttyv0)",
  389. run: "\x08", // backspace to avoid messing with login prompt
  390. },
  391. {
  392. on_text: "login:",
  393. after: 1000,
  394. run: "root\n",
  395. },
  396. {
  397. on_text: "Password:",
  398. after: 1000,
  399. run: "\n",
  400. },
  401. ],
  402. },
  403. {
  404. name: "FreeBSD cdrom",
  405. skip_if_disk_image_missing: true,
  406. slow: 1,
  407. timeout: 10 * 60,
  408. cdrom: root_path + "/images/experimental/os/FreeBSD-11.0-RELEASE-i386-bootonly.iso",
  409. expected_texts: ["Welcome to FreeBSD!"],
  410. actions: [
  411. {
  412. on_text: " Autoboot in ",
  413. run: "\n",
  414. }
  415. ],
  416. },
  417. {
  418. name: "Arch Linux",
  419. skip_if_disk_image_missing: true,
  420. timeout: 20 * 60,
  421. bzimage_initrd_from_filesystem: true,
  422. cmdline: [
  423. "rw apm=off vga=0x344 video=vesafb:ypan,vremap:8",
  424. "root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose mitigations=off",
  425. "audit=0 init=/usr/bin/init-openrc net.ifnames=0 biosdevname=0",
  426. ].join(" "),
  427. filesystem: {
  428. basefs: "images/fs.json",
  429. baseurl: "images/arch-nongz/",
  430. },
  431. expected_texts: [
  432. "root@localhost",
  433. "aaaaaaaaaaaaaaaaaaaa",
  434. "Hello, world",
  435. "Hello from JS",
  436. "Hello from OCaml",
  437. "Compress okay",
  438. ],
  439. actions: [
  440. {
  441. on_text: "root@localhost",
  442. run: `python -c 'print(100 * "a")'\n`,
  443. },
  444. {
  445. on_text: "aaaaaaaaaaaaaaaaaaaa",
  446. run: `gcc hello.c && ./a.out\n`,
  447. },
  448. {
  449. on_text: "Hello, world",
  450. run: `echo 'console.log("Hello from JS")' | node\n`,
  451. },
  452. {
  453. on_text: "Hello from JS",
  454. run: `echo 'print_endline "Hello from OCaml"' > hello.ml && ocamlopt hello.ml && ./a.out\n`,
  455. },
  456. {
  457. on_text: "Hello from OCaml",
  458. run:
  459. "zstd hello.c && gzip -k hello.c && bzip2 -k hello.c && xz -k hello.c && lzma -k hello.c && " +
  460. "zstdcat hello.c.zst && zcat hello.c.gz && bzcat hello.c.bz2 && xzcat hello.c.xz && lzmadec hello.c.lzma && " +
  461. "echo Compress okay\n",
  462. },
  463. {
  464. on_text: "Compress okay",
  465. run: "./startx.sh\n",
  466. },
  467. ],
  468. expect_graphical_mode: true,
  469. expect_graphical_size: [1024, 768],
  470. expect_mouse_registered: true,
  471. },
  472. {
  473. name: "FreeGEM",
  474. skip_if_disk_image_missing: true,
  475. timeout: 60,
  476. hda: root_path + "/images/experimental/os/freegem.bin",
  477. expect_graphical_mode: true,
  478. expect_mouse_registered: true,
  479. actions: [
  480. {
  481. on_text: " Select from Menu",
  482. run: "3",
  483. }
  484. ],
  485. },
  486. {
  487. name: "Haiku",
  488. skip_if_disk_image_missing: true,
  489. timeout: 15 * 60,
  490. memory_size: 512 * 1024 * 1024,
  491. hda: root_path + "/images/haiku-r1beta2-hrev54154_111-x86_gcc2h-anyboot.iso",
  492. expected_serial_text: [
  493. "init_hardware()",
  494. "Running post install script /boot/system/boot/post-install/sshd_keymaker.sh",
  495. // After pressing enter in the boot dialog:
  496. "Running first login script /boot/system/boot/first-login/default_deskbar_items.sh",
  497. ],
  498. expect_graphical_mode: true,
  499. expect_graphical_size: [1024, 768],
  500. expect_mouse_registered: true,
  501. actions: [
  502. { after: 1 * 60 * 1000, run: "\n" },
  503. { after: 2 * 60 * 1000, run: "\n" },
  504. { after: 3 * 60 * 1000, run: "\n" },
  505. { after: 4 * 60 * 1000, run: "\n" },
  506. { after: 5 * 60 * 1000, run: "\n" },
  507. { after: 6 * 60 * 1000, run: "\n" },
  508. { after: 7 * 60 * 1000, run: "\n" },
  509. { after: 8 * 60 * 1000, run: "\n" },
  510. ],
  511. },
  512. {
  513. name: "9front",
  514. skip_if_disk_image_missing: true,
  515. acpi: true,
  516. timeout: 5 * 60,
  517. hda: root_path + "/images/9front-7781.38dcaeaa222c.386.iso",
  518. expect_graphical_mode: true,
  519. expect_graphical_size: [1024, 768],
  520. expect_mouse_registered: true,
  521. actions: [
  522. { after: 60 * 1000, run: "\n" },
  523. { after: 70 * 1000, run: "\n" },
  524. { after: 80 * 1000, run: "\n" },
  525. { after: 90 * 1000, run: "\n" },
  526. { after: 100 * 1000, run: "\n" },
  527. { after: 110 * 1000, run: "\n" },
  528. { after: 120 * 1000, run: "\n" },
  529. { after: 130 * 1000, run: "\n" },
  530. { after: 140 * 1000, run: "\n" },
  531. { after: 150 * 1000, run: "\n" },
  532. { after: 160 * 1000, run: "\n" },
  533. { after: 170 * 1000, run: "\n" },
  534. { after: 180 * 1000, run: "\n" },
  535. ],
  536. },
  537. {
  538. name: "ReactOS",
  539. skip_if_disk_image_missing: true,
  540. timeout: 10 * 60,
  541. hda: root_path + "/images/reactos-livecd-0.4.15-dev-73-g03c09c9-x86-gcc-lin-dbg.iso",
  542. expect_graphical_mode: true,
  543. expect_graphical_size: [800, 600],
  544. expect_mouse_registered: true,
  545. actions: [
  546. { after: 1 * 60 * 1000, run: "\n" },
  547. { after: 2 * 60 * 1000, run: "\n" },
  548. { after: 3 * 60 * 1000, run: "\n" },
  549. { after: 4 * 60 * 1000, run: "\n" },
  550. { after: 5 * 60 * 1000, run: "\n" },
  551. { after: 6 * 60 * 1000, run: "\n" },
  552. { after: 7 * 60 * 1000, run: "\n" },
  553. { after: 8 * 60 * 1000, run: "\n" },
  554. ],
  555. expected_serial_text: [
  556. "DnsIntCacheInitialize()",
  557. // when desktop is rendered:
  558. "err: Attempted to close thread desktop",
  559. ],
  560. },
  561. {
  562. name: "ReactOS CD",
  563. skip_if_disk_image_missing: true,
  564. timeout: 10 * 60,
  565. cdrom: root_path + "/images/reactos-livecd-0.4.15-dev-73-g03c09c9-x86-gcc-lin-dbg.iso",
  566. expect_graphical_mode: true,
  567. expect_graphical_size: [800, 600],
  568. expect_mouse_registered: true,
  569. expected_serial_text: ["DnsIntCacheInitialize()"],
  570. },
  571. {
  572. name: "HelenOS",
  573. skip_if_disk_image_missing: true,
  574. timeout: 3 * 60,
  575. cdrom: root_path + "/images/experimental/os/HelenOS-0.5.0-ia32.iso",
  576. expect_graphical_mode: true,
  577. expect_mouse_registered: true,
  578. },
  579. {
  580. name: "Minix",
  581. skip_if_disk_image_missing: true,
  582. timeout: 60,
  583. hda: root_path + "/images/experimental/os/minix2hd.img",
  584. actions: [
  585. {
  586. on_text: " = Start Minix",
  587. run: "=",
  588. },
  589. {
  590. on_text: "noname login:",
  591. run: "root\n",
  592. },
  593. ],
  594. expected_texts: ["noname login:", "# "],
  595. },
  596. {
  597. name: "Minix CD",
  598. skip_if_disk_image_missing: true,
  599. timeout: 3 * 60,
  600. cdrom: root_path + "/images/minix-3.3.0.iso",
  601. actions: [
  602. {
  603. on_text: "login:",
  604. run: "root\n",
  605. },
  606. ],
  607. expected_texts: ["login:", "We'd like your feedback", "# "],
  608. },
  609. {
  610. name: "Mobius",
  611. skip_if_disk_image_missing: true,
  612. timeout: 2 * 60,
  613. fda: root_path + "/images/mobius-fd-release5.img",
  614. expect_graphical_mode: true,
  615. actions: [
  616. {
  617. on_text: " The highlighted entry will be booted automatically",
  618. run: "\n",
  619. },
  620. ],
  621. },
  622. {
  623. name: "Tiny Core 11 CD",
  624. skip_if_disk_image_missing: 1,
  625. timeout: 5 * 60,
  626. cdrom: root_path + "/images/TinyCore-11.0.iso",
  627. expect_graphical_mode: true,
  628. expect_mouse_registered: true,
  629. actions: [{ on_text: " BIOS default device boot in", run: "\n", after: 5000 }],
  630. },
  631. {
  632. name: "Tiny Core 11 HD",
  633. skip_if_disk_image_missing: 1,
  634. timeout: 5 * 60,
  635. cdrom: root_path + "/images/TinyCore-11.0.iso",
  636. expect_graphical_mode: true,
  637. expect_mouse_registered: true,
  638. actions: [{ on_text: " BIOS default device boot in", run: "\n", after: 5000 }],
  639. },
  640. {
  641. name: "Core 9",
  642. skip_if_disk_image_missing: 1,
  643. timeout: 5 * 60,
  644. cdrom: root_path + "/images/experimental/os/Core-9.0.iso",
  645. expected_texts: ["tc@box"],
  646. actions: [{ on_text: "boot:", run: "\n" }],
  647. },
  648. {
  649. name: "Core 8",
  650. skip_if_disk_image_missing: 1,
  651. timeout: 5 * 60,
  652. cdrom: root_path + "/images/experimental/os/Core-8.0.iso",
  653. expected_texts: ["tc@box"],
  654. actions: [{ on_text: "boot:", run: "\n" }],
  655. },
  656. {
  657. name: "Core 7",
  658. skip_if_disk_image_missing: 1,
  659. timeout: 5 * 60,
  660. cdrom: root_path + "/images/experimental/os/Core-7.2.iso",
  661. expected_texts: ["tc@box"],
  662. actions: [{ on_text: "boot:", run: "\n" }],
  663. },
  664. {
  665. name: "Core 6",
  666. skip_if_disk_image_missing: 1,
  667. timeout: 5 * 60,
  668. cdrom: root_path + "/images/experimental/os/Core-6.4.1.iso",
  669. expected_texts: ["tc@box"],
  670. actions: [{ on_text: "boot:", run: "\n" }],
  671. },
  672. {
  673. name: "Core 5",
  674. skip_if_disk_image_missing: 1,
  675. timeout: 5 * 60,
  676. cdrom: root_path + "/images/experimental/os/Core-5.4.iso",
  677. expected_texts: ["tc@box"],
  678. actions: [{ on_text: "boot:", run: "\n" }],
  679. },
  680. {
  681. name: "Core 4",
  682. skip_if_disk_image_missing: 1,
  683. timeout: 5 * 60,
  684. cdrom: root_path + "/images/experimental/os/Core-4.7.7.iso",
  685. expected_texts: ["tc@box"],
  686. actions: [{ on_text: "boot:", run: "\n" }],
  687. },
  688. {
  689. name: "Damn Small Linux",
  690. skip_if_disk_image_missing: 1,
  691. timeout: 5 * 60,
  692. cdrom: root_path + "/images/dsl-4.11.rc2.iso",
  693. expect_graphical_mode: true,
  694. expect_graphical_size: [1024, 768],
  695. expect_mouse_registered: true,
  696. },
  697. ];
  698. if(TEST_NAME)
  699. {
  700. tests = tests.filter(test => test.name === TEST_NAME);
  701. }
  702. var nr_of_cpus = Math.min(Math.round(os.cpus().length / 2) || 1, tests.length, MAX_PARALLEL_TESTS);
  703. console.log("Using %d cpus", nr_of_cpus);
  704. var current_test = 0;
  705. for(var i = 0; i < nr_of_cpus; i++)
  706. {
  707. var worker = cluster.fork();
  708. worker.on("message", send_work_to_worker.bind(null, worker));
  709. worker.on("online", send_work_to_worker.bind(null, worker));
  710. worker.on("exit", function(code, signal)
  711. {
  712. if(signal)
  713. {
  714. console.warn("Worker killed by signal " + signal);
  715. process.exit(1);
  716. }
  717. else if(code !== 0)
  718. {
  719. process.exit(code);
  720. }
  721. });
  722. worker.on("error", function(error)
  723. {
  724. console.error("Worker error: ", error.toString(), error);
  725. process.exit(1);
  726. });
  727. }
  728. }
  729. else
  730. {
  731. cluster.worker.on("message", function(test_case)
  732. {
  733. run_test(test_case, function()
  734. {
  735. process.send("I'm done");
  736. });
  737. });
  738. }
  739. function bytearray_starts_with(arr, search)
  740. {
  741. for(var i = 0; i < search.length; i++)
  742. {
  743. if(arr[i] !== search[i])
  744. {
  745. return false;
  746. }
  747. }
  748. return true;
  749. }
  750. function run_test(test, done)
  751. {
  752. console.log("Starting test: %s", test.name);
  753. let image = test.fda || test.hda || test.cdrom || test.bzimage || test.filesystem && test.filesystem.basefs;
  754. assert(image, "Bootable drive expected");
  755. if(!fs.existsSync(image))
  756. {
  757. if(test.skip_if_disk_image_missing)
  758. {
  759. console.warn("Missing disk image: " + image + ", test skipped");
  760. console.warn();
  761. done();
  762. return;
  763. }
  764. else
  765. {
  766. console.warn("Missing disk image: " + image);
  767. process.exit(1);
  768. }
  769. }
  770. if(test.slow && !RUN_SLOW_TESTS)
  771. {
  772. console.warn("Slow test: " + test.name + ", skipped");
  773. console.warn();
  774. done();
  775. return;
  776. }
  777. if(test.alternative_bios)
  778. {
  779. var bios = root_path + "/bios/bochs-bios.bin";
  780. var vga_bios = root_path + "/bios/bochs-vgabios.bin";
  781. }
  782. else if(TEST_RELEASE_BUILD)
  783. {
  784. var bios = root_path + "/bios/seabios.bin";
  785. var vga_bios = root_path + "/bios/vgabios.bin";
  786. }
  787. else
  788. {
  789. var bios = root_path + "/bios/seabios-debug.bin";
  790. var vga_bios = root_path + "/bios/vgabios-debug.bin";
  791. }
  792. var settings = {
  793. bios: { url: bios },
  794. vga_bios: { url: vga_bios },
  795. autostart: true,
  796. memory_size: test.memory_size || 128 * 1024 * 1024,
  797. log_level: 0,
  798. cmdline: test.cmdline,
  799. };
  800. if(test.cdrom)
  801. {
  802. settings.cdrom = { url: test.cdrom };
  803. }
  804. if(test.fda)
  805. {
  806. settings.fda = { url: test.fda };
  807. }
  808. if(test.hda)
  809. {
  810. settings.hda = { url: test.hda, async: true };
  811. }
  812. if(test.bzimage)
  813. {
  814. settings.bzimage = { url: test.bzimage };
  815. }
  816. if(test.filesystem)
  817. {
  818. settings.filesystem = test.filesystem;
  819. }
  820. settings.cmdline = test.cmdline;
  821. settings.bzimage_initrd_from_filesystem = test.bzimage_initrd_from_filesystem;
  822. settings.acpi = test.acpi;
  823. if(test.expected_texts)
  824. {
  825. test.expected_texts = test.expected_texts.map(string_to_bytearray);
  826. }
  827. else
  828. {
  829. test.expected_texts = [];
  830. }
  831. if(!test.expected_serial_text)
  832. {
  833. test.expected_serial_text = [];
  834. }
  835. var emulator = new V86(settings);
  836. var screen = new Uint8Array(SCREEN_WIDTH * 25);
  837. function check_text_test_done()
  838. {
  839. return test.expected_texts.length === 0;
  840. }
  841. function check_serial_test_done()
  842. {
  843. return test.expected_serial_text.length === 0;
  844. }
  845. var mouse_test_done = false;
  846. function check_mouse_test_done()
  847. {
  848. return !test.expect_mouse_registered || mouse_test_done;
  849. }
  850. var graphical_test_done = false;
  851. var size_test_done = false;
  852. function check_graphical_test_done()
  853. {
  854. return !test.expect_graphical_mode || (graphical_test_done && (!test.expect_graphical_size || size_test_done));
  855. }
  856. var test_start = Date.now();
  857. var timeout_seconds = test.timeout * TIMEOUT_EXTRA_FACTOR;
  858. var timeout = setTimeout(check_test_done, (timeout_seconds + 1) * 1000);
  859. var timeouts = [timeout];
  860. var on_text = [];
  861. var stopped = false;
  862. var screen_interval = null;
  863. function check_test_done()
  864. {
  865. if(stopped)
  866. {
  867. return;
  868. }
  869. if(check_text_test_done() &&
  870. check_mouse_test_done() &&
  871. check_graphical_test_done() &&
  872. check_serial_test_done())
  873. {
  874. var end = Date.now();
  875. for(let timeout of timeouts) clearTimeout(timeout);
  876. stopped = true;
  877. emulator.stop();
  878. if(screen_interval !== null)
  879. {
  880. clearInterval(screen_interval);
  881. }
  882. console.warn("Passed test: %s (took %ds)", test.name, (end - test_start) / 1000);
  883. console.warn();
  884. done();
  885. }
  886. else if(Date.now() >= test_start + timeout_seconds * 1000)
  887. {
  888. for(let timeout of timeouts) clearTimeout(timeout);
  889. stopped = true;
  890. if(screen_interval !== null)
  891. {
  892. clearInterval(screen_interval);
  893. }
  894. emulator.stop();
  895. emulator.destroy();
  896. if(test.failure_allowed)
  897. {
  898. console.warn("Test failed: %s (failure allowed)\n", test.name);
  899. }
  900. else
  901. {
  902. console.warn(screen_to_text(screen));
  903. console.warn("Test failed: %s\n", test.name);
  904. }
  905. if(!check_text_test_done())
  906. {
  907. console.warn('Expected text "%s" after %d seconds.', bytearray_to_string(test.expected_texts[0]), timeout_seconds);
  908. }
  909. if(!check_graphical_test_done())
  910. {
  911. console.warn("Expected graphical mode after %d seconds.", timeout_seconds);
  912. }
  913. if(!check_mouse_test_done())
  914. {
  915. console.warn("Expected mouse activation after %d seconds.", timeout_seconds);
  916. }
  917. if(!check_serial_test_done())
  918. {
  919. console.warn('Expected serial text "%s" after %d seconds.', test.expected_serial_text, timeout_seconds);
  920. }
  921. if(on_text.length)
  922. {
  923. console.warn(`Note: Expected text "${bytearray_to_string(on_text[0].text)}" to run "${on_text[0].run}"`);
  924. }
  925. if(!test.failure_allowed)
  926. {
  927. process.exit(1);
  928. }
  929. else
  930. {
  931. done();
  932. }
  933. }
  934. }
  935. emulator.add_listener("mouse-enable", function()
  936. {
  937. mouse_test_done = true;
  938. check_test_done();
  939. });
  940. emulator.add_listener("screen-set-mode", function(is_graphical)
  941. {
  942. graphical_test_done = is_graphical;
  943. check_test_done();
  944. });
  945. emulator.add_listener("screen-set-size-graphical", function(size)
  946. {
  947. if(test.expect_graphical_size)
  948. {
  949. size_test_done = size[0] === test.expect_graphical_size[0] &&
  950. size[1] === test.expect_graphical_size[1];
  951. check_test_done();
  952. }
  953. });
  954. emulator.add_listener("screen-put-char", function(chr)
  955. {
  956. var y = chr[0];
  957. var x = chr[1];
  958. var code = chr[2];
  959. screen[x + SCREEN_WIDTH * y] = code;
  960. var line = get_line(screen, y);
  961. if(!check_text_test_done())
  962. {
  963. let expected = test.expected_texts[0];
  964. if(x < expected.length && bytearray_starts_with(line, expected))
  965. {
  966. test.expected_texts.shift();
  967. if(VERBOSE) console.log(`Passed: "${bytearray_to_string(expected)}" on screen (${test.name})`);
  968. check_test_done();
  969. }
  970. }
  971. if(on_text.length)
  972. {
  973. let expected = on_text[0].text;
  974. if(x < expected.length && bytearray_starts_with(line, expected))
  975. {
  976. var action = on_text.shift();
  977. timeouts.push(
  978. setTimeout(() => {
  979. if(VERBOSE) console.error("Sending '%s'", action.run);
  980. emulator.keyboard_send_text(action.run);
  981. }, action.after || 0)
  982. );
  983. }
  984. }
  985. });
  986. if(LOG_SCREEN)
  987. {
  988. screen_interval = setInterval(() => {
  989. console.warn(screen_to_text(screen));
  990. }, 10000);
  991. }
  992. let serial_line = "";
  993. emulator.add_listener("serial0-output-char", function(c)
  994. {
  995. if(c === "\n")
  996. {
  997. if(VERBOSE)
  998. {
  999. console.log(`Serial (${test.name}):`, serial_line);
  1000. }
  1001. if(test.expected_serial_text.length)
  1002. {
  1003. const expected = test.expected_serial_text[0];
  1004. if(serial_line.includes(expected))
  1005. {
  1006. test.expected_serial_text.shift();
  1007. if(VERBOSE) console.log(`Passed: "${expected}" on serial (${test.name})`);
  1008. check_test_done();
  1009. }
  1010. }
  1011. serial_line = "";
  1012. }
  1013. else if(c >= " " && c <= "~")
  1014. {
  1015. serial_line += c;
  1016. }
  1017. });
  1018. test.actions && test.actions.forEach(function(action)
  1019. {
  1020. if(action.on_text)
  1021. {
  1022. on_text.push({ text: string_to_bytearray(action.on_text), run: action.run, after: action.after });
  1023. }
  1024. else
  1025. {
  1026. timeouts.push(
  1027. setTimeout(() => {
  1028. if(VERBOSE) console.error("Sending '%s'", action.run);
  1029. emulator.keyboard_send_text(action.run);
  1030. }, action.after || 0)
  1031. );
  1032. }
  1033. });
  1034. }