tioselectors.nim 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. discard """
  2. output: "All tests passed!"
  3. """
  4. import selectors
  5. const hasThreadSupport = compileOption("threads")
  6. template processTest(t, x: untyped) =
  7. #stdout.write(t)
  8. #stdout.flushFile()
  9. if not x: echo(t & " FAILED\r\n")
  10. when not defined(windows):
  11. import os, posix, nativesockets
  12. when ioselSupportedPlatform:
  13. import osproc
  14. proc socket_notification_test(): bool =
  15. proc create_test_socket(): SocketHandle =
  16. var sock = posix.socket(posix.AF_INET, posix.SOCK_STREAM,
  17. posix.IPPROTO_TCP)
  18. var x: int = fcntl(sock, F_GETFL, 0)
  19. if x == -1: raiseOSError(osLastError())
  20. else:
  21. var mode = x or O_NONBLOCK
  22. if fcntl(sock, F_SETFL, mode) == -1:
  23. raiseOSError(osLastError())
  24. result = sock
  25. var client_message = "SERVER HELLO =>"
  26. var server_message = "CLIENT HELLO"
  27. var buffer : array[128, char]
  28. var selector = newSelector[int]()
  29. var client_socket = create_test_socket()
  30. var server_socket = create_test_socket()
  31. var option : int32 = 1
  32. if setsockopt(server_socket, cint(SOL_SOCKET), cint(SO_REUSEADDR),
  33. addr(option), sizeof(option).SockLen) < 0:
  34. raiseOSError(osLastError())
  35. var aiList = getAddrInfo("0.0.0.0", Port(13337))
  36. if bindAddr(server_socket, aiList.ai_addr,
  37. aiList.ai_addrlen.Socklen) < 0'i32:
  38. freeAddrInfo(aiList)
  39. raiseOSError(osLastError())
  40. if server_socket.listen() == -1:
  41. raiseOSError(osLastError())
  42. freeAddrInfo(aiList)
  43. aiList = getAddrInfo("127.0.0.1", Port(13337))
  44. discard posix.connect(client_socket, aiList.ai_addr,
  45. aiList.ai_addrlen.Socklen)
  46. registerHandle(selector, server_socket, {Event.Read}, 0)
  47. registerHandle(selector, client_socket, {Event.Write}, 0)
  48. freeAddrInfo(aiList)
  49. discard selector.select(100)
  50. var sockAddress: SockAddr
  51. var addrLen = sizeof(sockAddress).Socklen
  52. var server2_socket = accept(server_socket,
  53. cast[ptr SockAddr](addr(sockAddress)),
  54. addr(addrLen))
  55. assert(server2_socket != osInvalidSocket)
  56. selector.registerHandle(server2_socket, {Event.Read}, 0)
  57. if posix.send(client_socket, addr(client_message[0]),
  58. len(client_message), 0) == -1:
  59. raiseOSError(osLastError())
  60. selector.updateHandle(client_socket, {Event.Read})
  61. var rc2 = selector.select(100)
  62. assert(len(rc2) == 1)
  63. var read_count = posix.recv(server2_socket, addr buffer[0], 128, 0)
  64. if read_count == -1:
  65. raiseOSError(osLastError())
  66. assert(read_count == len(client_message))
  67. var test1 = true
  68. for i in 0..<read_count:
  69. if client_message[i] != buffer[i]:
  70. test1 = false
  71. break
  72. assert(test1)
  73. selector.updateHandle(server2_socket, {Event.Write})
  74. var rc3 = selector.select(0)
  75. assert(len(rc3) == 1)
  76. if posix.send(server2_socket, addr(server_message[0]),
  77. len(server_message), 0) == -1:
  78. raiseOSError(osLastError())
  79. selector.updateHandle(server2_socket, {Event.Read})
  80. var rc4 = selector.select(100)
  81. assert(len(rc4) == 1)
  82. read_count = posix.recv(client_socket, addr(buffer[0]), 128, 0)
  83. if read_count == -1:
  84. raiseOSError(osLastError())
  85. assert(read_count == len(server_message))
  86. var test2 = true
  87. for i in 0..<read_count:
  88. if server_message[i] != buffer[i]:
  89. test2 = false
  90. break
  91. assert(test2)
  92. selector.unregister(server_socket)
  93. selector.unregister(server2_socket)
  94. selector.unregister(client_socket)
  95. discard posix.close(server_socket)
  96. discard posix.close(server2_socket)
  97. discard posix.close(client_socket)
  98. assert(selector.isEmpty())
  99. close(selector)
  100. result = true
  101. proc event_notification_test(): bool =
  102. var selector = newSelector[int]()
  103. var event = newSelectEvent()
  104. selector.registerEvent(event, 1)
  105. var rc0 = selector.select(0)
  106. event.trigger()
  107. var rc1 = selector.select(0)
  108. event.trigger()
  109. var rc2 = selector.select(0)
  110. var rc3 = selector.select(0)
  111. assert(len(rc0) == 0 and len(rc1) == 1 and len(rc2) == 1 and len(rc3) == 0)
  112. var ev1 = selector.getData(rc1[0].fd)
  113. var ev2 = selector.getData(rc2[0].fd)
  114. assert(ev1 == 1 and ev2 == 1)
  115. selector.unregister(event)
  116. event.close()
  117. assert(selector.isEmpty())
  118. selector.close()
  119. result = true
  120. when ioselSupportedPlatform:
  121. proc timer_notification_test(): bool =
  122. var selector = newSelector[int]()
  123. var timer = selector.registerTimer(100, false, 0)
  124. var rc1 = selector.select(10000)
  125. var rc2 = selector.select(10000)
  126. # if this flakes, see tests/m14634.nim
  127. assert len(rc1) == 1 and len(rc2) == 1, $(len(rc1), len(rc2))
  128. selector.unregister(timer)
  129. discard selector.select(0)
  130. selector.registerTimer(100, true, 0)
  131. var rc4 = selector.select(10000)
  132. var rc5 = selector.select(1000) # this will be an actual wait, keep it small
  133. assert len(rc4) == 1 and len(rc5) == 0, $(len(rc4), len(rc5))
  134. assert(selector.isEmpty())
  135. selector.close()
  136. result = true
  137. proc process_notification_test(): bool =
  138. var selector = newSelector[int]()
  139. var process2 = startProcess("sleep", "", ["2"], nil,
  140. {poStdErrToStdOut, poUsePath})
  141. discard startProcess("sleep", "", ["1"], nil,
  142. {poStdErrToStdOut, poUsePath})
  143. selector.registerProcess(process2.processID, 0)
  144. var rc1 = selector.select(1500)
  145. var rc2 = selector.select(1500)
  146. var r = len(rc1) + len(rc2)
  147. assert(r == 1)
  148. result = true
  149. proc signal_notification_test(): bool =
  150. var sigset1n, sigset1o, sigset2n, sigset2o: Sigset
  151. var pid = posix.getpid()
  152. discard sigemptyset(sigset1n)
  153. discard sigemptyset(sigset1o)
  154. discard sigemptyset(sigset2n)
  155. discard sigemptyset(sigset2o)
  156. when hasThreadSupport:
  157. if pthread_sigmask(SIG_BLOCK, sigset1n, sigset1o) == -1:
  158. raiseOSError(osLastError())
  159. else:
  160. if sigprocmask(SIG_BLOCK, sigset1n, sigset1o) == -1:
  161. raiseOSError(osLastError())
  162. var selector = newSelector[int]()
  163. var s1 = selector.registerSignal(SIGUSR1, 1)
  164. var s2 = selector.registerSignal(SIGUSR2, 2)
  165. var s3 = selector.registerSignal(SIGTERM, 3)
  166. discard selector.select(0)
  167. discard posix.kill(pid, SIGUSR1)
  168. discard posix.kill(pid, SIGUSR2)
  169. discard posix.kill(pid, SIGTERM)
  170. var rc = selector.select(0)
  171. var cd0 = selector.getData(rc[0].fd)
  172. var cd1 = selector.getData(rc[1].fd)
  173. var cd2 = selector.getData(rc[2].fd)
  174. selector.unregister(s1)
  175. selector.unregister(s2)
  176. selector.unregister(s3)
  177. when hasThreadSupport:
  178. if pthread_sigmask(SIG_BLOCK, sigset2n, sigset2o) == -1:
  179. raiseOSError(osLastError())
  180. else:
  181. if sigprocmask(SIG_BLOCK, sigset2n, sigset2o) == -1:
  182. raiseOSError(osLastError())
  183. assert(len(rc) == 3)
  184. assert(cd0 + cd1 + cd2 == 6, $(cd0 + cd1 + cd2)) # 1 + 2 + 3
  185. assert(equalMem(addr sigset1o, addr sigset2o, sizeof(Sigset)))
  186. assert(selector.isEmpty())
  187. result = true
  188. when defined(macosx) or defined(freebsd) or defined(openbsd) or
  189. defined(netbsd):
  190. proc rename(frompath: cstring, topath: cstring): cint
  191. {.importc: "rename", header: "<stdio.h>".}
  192. proc createFile(name: string): cint =
  193. result = posix.open(cstring(name), posix.O_CREAT or posix.O_RDWR)
  194. if result == -1:
  195. raiseOsError(osLastError())
  196. proc writeFile(name: string, data: string) =
  197. let fd = posix.open(cstring(name), posix.O_APPEND or posix.O_RDWR)
  198. if fd == -1:
  199. raiseOsError(osLastError())
  200. let length = len(data).cint
  201. if posix.write(fd, cast[pointer](addr data[0]),
  202. len(data).cint) != length:
  203. raiseOsError(osLastError())
  204. if posix.close(fd) == -1:
  205. raiseOsError(osLastError())
  206. proc closeFile(fd: cint) =
  207. if posix.close(fd) == -1:
  208. raiseOsError(osLastError())
  209. proc removeFile(name: string) =
  210. let err = posix.unlink(cstring(name))
  211. if err == -1:
  212. raiseOsError(osLastError())
  213. proc createDir(name: string) =
  214. let err = posix.mkdir(cstring(name), 0x1FF)
  215. if err == -1:
  216. raiseOsError(osLastError())
  217. proc removeDir(name: string) =
  218. let err = posix.rmdir(cstring(name))
  219. if err == -1:
  220. raiseOsError(osLastError())
  221. proc chmodPath(name: string, mode: cint) =
  222. let err = posix.chmod(cstring(name), Mode(mode))
  223. if err == -1:
  224. raiseOsError(osLastError())
  225. proc renameFile(names: string, named: string) =
  226. let err = rename(cstring(names), cstring(named))
  227. if err == -1:
  228. raiseOsError(osLastError())
  229. proc symlink(names: string, named: string) =
  230. let err = posix.symlink(cstring(names), cstring(named))
  231. if err == -1:
  232. raiseOsError(osLastError())
  233. proc openWatch(name: string): cint =
  234. result = posix.open(cstring(name), posix.O_RDONLY)
  235. if result == -1:
  236. raiseOsError(osLastError())
  237. const
  238. testDirectory = "/tmp/kqtest"
  239. type
  240. valType = object
  241. fd: cint
  242. events: set[Event]
  243. proc vnode_test(): bool =
  244. proc validate(test: openArray[ReadyKey],
  245. check: openArray[valType]): bool =
  246. result = false
  247. if len(test) == len(check):
  248. for checkItem in check:
  249. result = false
  250. for testItem in test:
  251. if testItem.fd == checkItem.fd and
  252. checkItem.events <= testItem.events:
  253. result = true
  254. break
  255. if not result:
  256. break
  257. var res: seq[ReadyKey]
  258. var selector = newSelector[int]()
  259. var events = {Event.VnodeWrite, Event.VnodeDelete, Event.VnodeExtend,
  260. Event.VnodeAttrib, Event.VnodeLink, Event.VnodeRename,
  261. Event.VnodeRevoke}
  262. result = true
  263. discard posix.unlink(testDirectory)
  264. createDir(testDirectory)
  265. var dirfd = posix.open(cstring(testDirectory), posix.O_RDONLY)
  266. if dirfd == -1:
  267. raiseOsError(osLastError())
  268. selector.registerVnode(dirfd, events, 1)
  269. discard selector.select(0)
  270. # chmod testDirectory to 0777
  271. chmodPath(testDirectory, 0x1FF)
  272. res = selector.select(0)
  273. doAssert(len(res) == 1)
  274. doAssert(len(selector.select(0)) == 0)
  275. doAssert(res[0].fd == dirfd and
  276. {Event.Vnode, Event.VnodeAttrib} <= res[0].events)
  277. # create subdirectory
  278. createDir(testDirectory & "/test")
  279. res = selector.select(0)
  280. doAssert(len(res) == 1)
  281. doAssert(len(selector.select(0)) == 0)
  282. doAssert(res[0].fd == dirfd and
  283. {Event.Vnode, Event.VnodeWrite,
  284. Event.VnodeLink} <= res[0].events)
  285. # open test directory for watching
  286. var testfd = openWatch(testDirectory & "/test")
  287. selector.registerVnode(testfd, events, 2)
  288. doAssert(len(selector.select(0)) == 0)
  289. # rename test directory
  290. renameFile(testDirectory & "/test", testDirectory & "/renamed")
  291. res = selector.select(0)
  292. doAssert(len(res) == 2)
  293. doAssert(len(selector.select(0)) == 0)
  294. doAssert(validate(res,
  295. [valType(fd: dirfd, events: {Event.Vnode, Event.VnodeWrite}),
  296. valType(fd: testfd,
  297. events: {Event.Vnode, Event.VnodeRename})])
  298. )
  299. # remove test directory
  300. removeDir(testDirectory & "/renamed")
  301. res = selector.select(0)
  302. doAssert(len(res) == 2)
  303. doAssert(len(selector.select(0)) == 0)
  304. doAssert(validate(res,
  305. [valType(fd: dirfd, events: {Event.Vnode, Event.VnodeWrite,
  306. Event.VnodeLink}),
  307. valType(fd: testfd,
  308. events: {Event.Vnode, Event.VnodeDelete})])
  309. )
  310. # create file new test file
  311. testfd = createFile(testDirectory & "/testfile")
  312. res = selector.select(0)
  313. doAssert(len(res) == 1)
  314. doAssert(len(selector.select(0)) == 0)
  315. doAssert(res[0].fd == dirfd and
  316. {Event.Vnode, Event.VnodeWrite} <= res[0].events)
  317. # close new test file
  318. closeFile(testfd)
  319. doAssert(len(selector.select(0)) == 0)
  320. doAssert(len(selector.select(0)) == 0)
  321. # chmod test file with 0666
  322. chmodPath(testDirectory & "/testfile", 0x1B6)
  323. doAssert(len(selector.select(0)) == 0)
  324. testfd = openWatch(testDirectory & "/testfile")
  325. selector.registerVnode(testfd, events, 1)
  326. discard selector.select(0)
  327. # write data to test file
  328. writeFile(testDirectory & "/testfile", "TESTDATA")
  329. res = selector.select(0)
  330. doAssert(len(res) == 1)
  331. doAssert(len(selector.select(0)) == 0)
  332. doAssert(res[0].fd == testfd and
  333. {Event.Vnode, Event.VnodeWrite,
  334. Event.VnodeExtend} <= res[0].events)
  335. # symlink test file
  336. symlink(testDirectory & "/testfile", testDirectory & "/testlink")
  337. res = selector.select(0)
  338. doAssert(len(res) == 1)
  339. doAssert(len(selector.select(0)) == 0)
  340. doAssert(res[0].fd == dirfd and
  341. {Event.Vnode, Event.VnodeWrite} <= res[0].events)
  342. # remove test file
  343. removeFile(testDirectory & "/testfile")
  344. res = selector.select(0)
  345. doAssert(len(res) == 2)
  346. doAssert(len(selector.select(0)) == 0)
  347. doAssert(validate(res,
  348. [valType(fd: testfd, events: {Event.Vnode, Event.VnodeDelete}),
  349. valType(fd: dirfd, events: {Event.Vnode, Event.VnodeWrite})])
  350. )
  351. # remove symlink
  352. removeFile(testDirectory & "/testlink")
  353. res = selector.select(0)
  354. doAssert(len(res) == 1)
  355. doAssert(len(selector.select(0)) == 0)
  356. doAssert(res[0].fd == dirfd and
  357. {Event.Vnode, Event.VnodeWrite} <= res[0].events)
  358. # remove testDirectory
  359. removeDir(testDirectory)
  360. res = selector.select(0)
  361. doAssert(len(res) == 1)
  362. doAssert(len(selector.select(0)) == 0)
  363. doAssert(res[0].fd == dirfd and
  364. {Event.Vnode, Event.VnodeDelete} <= res[0].events)
  365. when hasThreadSupport:
  366. var counter = 0
  367. proc event_wait_thread(event: SelectEvent) {.thread.} =
  368. var selector = newSelector[int]()
  369. selector.registerEvent(event, 1)
  370. var rc = selector.select(1000)
  371. if len(rc) == 1:
  372. inc(counter)
  373. selector.unregister(event)
  374. assert(selector.isEmpty())
  375. proc mt_event_test(): bool =
  376. var
  377. thr: array[0..7, Thread[SelectEvent]]
  378. var selector = newSelector[int]()
  379. var sock = createNativeSocket()
  380. var event = newSelectEvent()
  381. for i in 0..high(thr):
  382. createThread(thr[i], event_wait_thread, event)
  383. selector.registerHandle(sock, {Event.Read}, 1)
  384. discard selector.select(500)
  385. selector.unregister(sock)
  386. event.trigger()
  387. joinThreads(thr)
  388. assert(counter == 1)
  389. result = true
  390. processTest("Socket notification test...", socket_notification_test())
  391. processTest("User event notification test...", event_notification_test())
  392. when hasThreadSupport:
  393. processTest("Multithreaded user event notification test...",
  394. mt_event_test())
  395. when ioselSupportedPlatform:
  396. processTest("Timer notification test...", timer_notification_test())
  397. processTest("Process notification test...", process_notification_test())
  398. processTest("Signal notification test...", signal_notification_test())
  399. when defined(macosx) or defined(freebsd) or defined(openbsd) or
  400. defined(netbsd):
  401. processTest("File notification test...", vnode_test())
  402. echo("All tests passed!")
  403. else:
  404. import nativesockets, winlean, os, osproc
  405. proc socket_notification_test(): bool =
  406. proc create_test_socket(): SocketHandle =
  407. var sock = createNativeSocket()
  408. setBlocking(sock, false)
  409. result = sock
  410. var client_message = "SERVER HELLO =>"
  411. var server_message = "CLIENT HELLO"
  412. var buffer : array[128, char]
  413. var selector = newSelector[int]()
  414. var client_socket = create_test_socket()
  415. var server_socket = create_test_socket()
  416. selector.registerHandle(server_socket, {Event.Read}, 0)
  417. selector.registerHandle(client_socket, {Event.Write}, 0)
  418. var option : int32 = 1
  419. if setsockopt(server_socket, cint(SOL_SOCKET), cint(SO_REUSEADDR),
  420. addr(option), sizeof(option).SockLen) < 0:
  421. raiseOSError(osLastError())
  422. var aiList = getAddrInfo("0.0.0.0", Port(13337))
  423. if bindAddr(server_socket, aiList.ai_addr,
  424. aiList.ai_addrlen.Socklen) < 0'i32:
  425. freeAddrInfo(aiList)
  426. raiseOSError(osLastError())
  427. discard server_socket.listen()
  428. freeAddrInfo(aiList)
  429. aiList = getAddrInfo("127.0.0.1", Port(13337))
  430. discard connect(client_socket, aiList.ai_addr,
  431. aiList.ai_addrlen.Socklen)
  432. freeAddrInfo(aiList)
  433. # for some reason Windows select doesn't return both
  434. # descriptors from first call, so we need to make 2 calls
  435. var n = 0
  436. var rcm = selector.select(1000)
  437. while n < 10 and len(rcm) < 2:
  438. sleep(1000)
  439. rcm = selector.select(1000)
  440. inc(n)
  441. assert(len(rcm) == 2)
  442. var sockAddress = SockAddr()
  443. var addrLen = sizeof(sockAddress).Socklen
  444. var server2_socket = accept(server_socket,
  445. cast[ptr SockAddr](addr(sockAddress)),
  446. addr(addrLen))
  447. assert(server2_socket != osInvalidSocket)
  448. selector.registerHandle(server2_socket, {Event.Read}, 0)
  449. if send(client_socket, cast[pointer](addr(client_message[0])),
  450. cint(len(client_message)), 0) == -1:
  451. raiseOSError(osLastError())
  452. selector.updateHandle(client_socket, {Event.Read})
  453. var rc2 = selector.select(1000)
  454. assert(len(rc2) == 1)
  455. var read_count = recv(server2_socket, addr buffer[0], 128, 0)
  456. if read_count == -1:
  457. raiseOSError(osLastError())
  458. assert(read_count == len(client_message))
  459. var test1 = true
  460. for i in 0..<read_count:
  461. if client_message[i] != buffer[i]:
  462. test1 = false
  463. break
  464. assert(test1)
  465. if send(server2_socket, cast[pointer](addr(server_message[0])),
  466. cint(len(server_message)), 0) == -1:
  467. raiseOSError(osLastError())
  468. var rc3 = selector.select(0)
  469. assert(len(rc3) == 1)
  470. read_count = recv(client_socket, addr(buffer[0]), 128, 0)
  471. if read_count == -1:
  472. raiseOSError(osLastError())
  473. assert(read_count == len(server_message))
  474. var test2 = true
  475. for i in 0..<read_count:
  476. if server_message[i] != buffer[i]:
  477. test2 = false
  478. break
  479. assert(test2)
  480. selector.unregister(server_socket)
  481. selector.unregister(server2_socket)
  482. selector.unregister(client_socket)
  483. close(server_socket)
  484. close(server2_socket)
  485. close(client_socket)
  486. assert(selector.isEmpty())
  487. close(selector)
  488. result = true
  489. proc event_notification_test(): bool =
  490. var selector = newSelector[int]()
  491. var event = newSelectEvent()
  492. selector.registerEvent(event, 1)
  493. discard selector.select(0)
  494. event.trigger()
  495. var rc1 = selector.select(0)
  496. event.trigger()
  497. var rc2 = selector.select(0)
  498. var rc3 = selector.select(0)
  499. assert(len(rc1) == 1 and len(rc2) == 1 and len(rc3) == 0)
  500. var ev1 = selector.getData(rc1[0].fd)
  501. var ev2 = selector.getData(rc2[0].fd)
  502. assert(ev1 == 1 and ev2 == 1)
  503. selector.unregister(event)
  504. event.close()
  505. assert(selector.isEmpty())
  506. selector.close()
  507. result = true
  508. when hasThreadSupport:
  509. var counter = 0
  510. proc event_wait_thread(event: SelectEvent) {.thread.} =
  511. var selector = newSelector[int]()
  512. selector.registerEvent(event, 1)
  513. var rc = selector.select(1500)
  514. if len(rc) == 1:
  515. inc(counter)
  516. selector.unregister(event)
  517. assert(selector.isEmpty())
  518. proc mt_event_test(): bool =
  519. var thr: array[0..7, Thread[SelectEvent]]
  520. var event = newSelectEvent()
  521. for i in 0..high(thr):
  522. createThread(thr[i], event_wait_thread, event)
  523. event.trigger()
  524. joinThreads(thr)
  525. assert(counter == 1)
  526. result = true
  527. processTest("Socket notification test...", socket_notification_test())
  528. processTest("User event notification test...", event_notification_test())
  529. when hasThreadSupport:
  530. processTest("Multithreaded user event notification test...",
  531. mt_event_test())
  532. echo("All tests passed!")