run.js 33 KB

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