timeout.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Description: run various timeout tests
  5. *
  6. */
  7. #include <errno.h>
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <fcntl.h>
  13. #include <sys/time.h>
  14. #include <sys/wait.h>
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17. #include <sys/eventfd.h>
  18. #include "helpers.h"
  19. #include "liburing.h"
  20. #include "../src/syscall.h"
  21. #define TIMEOUT_MSEC 200
  22. static int not_supported;
  23. static int no_modify;
  24. static int no_multishot;
  25. static void msec_to_ts(struct __kernel_timespec *ts, unsigned int msec)
  26. {
  27. ts->tv_sec = msec / 1000;
  28. ts->tv_nsec = (msec % 1000) * 1000000;
  29. }
  30. /*
  31. * Test that we return to userspace if a timeout triggers, even if we
  32. * don't satisfy the number of events asked for.
  33. */
  34. static int test_single_timeout_many(struct io_uring *ring)
  35. {
  36. struct io_uring_cqe *cqe;
  37. struct io_uring_sqe *sqe;
  38. unsigned long long exp;
  39. struct __kernel_timespec ts;
  40. struct timeval tv;
  41. int ret;
  42. sqe = io_uring_get_sqe(ring);
  43. if (!sqe) {
  44. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  45. goto err;
  46. }
  47. msec_to_ts(&ts, TIMEOUT_MSEC);
  48. io_uring_prep_timeout(sqe, &ts, 0, 0);
  49. ret = io_uring_submit(ring);
  50. if (ret <= 0) {
  51. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  52. goto err;
  53. }
  54. gettimeofday(&tv, NULL);
  55. ret = __sys_io_uring_enter(ring->ring_fd, 0, 4, IORING_ENTER_GETEVENTS,
  56. NULL);
  57. if (ret < 0) {
  58. fprintf(stderr, "%s: io_uring_enter %d\n", __FUNCTION__, ret);
  59. goto err;
  60. }
  61. ret = io_uring_wait_cqe(ring, &cqe);
  62. if (ret < 0) {
  63. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  64. goto err;
  65. }
  66. ret = cqe->res;
  67. io_uring_cqe_seen(ring, cqe);
  68. if (ret == -EINVAL) {
  69. fprintf(stdout, "Timeout not supported, ignored\n");
  70. not_supported = 1;
  71. return 0;
  72. } else if (ret != -ETIME) {
  73. fprintf(stderr, "Timeout: %s\n", strerror(-ret));
  74. goto err;
  75. }
  76. exp = mtime_since_now(&tv);
  77. if (exp >= TIMEOUT_MSEC / 2 && exp <= (TIMEOUT_MSEC * 3) / 2)
  78. return 0;
  79. fprintf(stderr, "%s: Timeout seems wonky (got %llu)\n", __FUNCTION__, exp);
  80. err:
  81. return 1;
  82. }
  83. /*
  84. * Test numbered trigger of timeout
  85. */
  86. static int test_single_timeout_nr(struct io_uring *ring, int nr)
  87. {
  88. struct io_uring_cqe *cqe;
  89. struct io_uring_sqe *sqe;
  90. struct __kernel_timespec ts;
  91. int i, ret;
  92. sqe = io_uring_get_sqe(ring);
  93. if (!sqe) {
  94. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  95. goto err;
  96. }
  97. msec_to_ts(&ts, TIMEOUT_MSEC);
  98. io_uring_prep_timeout(sqe, &ts, nr, 0);
  99. sqe = io_uring_get_sqe(ring);
  100. io_uring_prep_nop(sqe);
  101. io_uring_sqe_set_data(sqe, (void *) 1);
  102. sqe = io_uring_get_sqe(ring);
  103. io_uring_prep_nop(sqe);
  104. io_uring_sqe_set_data(sqe, (void *) 1);
  105. ret = io_uring_submit_and_wait(ring, 3);
  106. if (ret <= 0) {
  107. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  108. goto err;
  109. }
  110. i = 0;
  111. while (i < 3) {
  112. ret = io_uring_wait_cqe(ring, &cqe);
  113. if (ret < 0) {
  114. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  115. goto err;
  116. }
  117. ret = cqe->res;
  118. /*
  119. * NOP commands have user_data as 1. Check that we get the
  120. * at least 'nr' NOPs first, then the successfully removed timeout.
  121. */
  122. if (io_uring_cqe_get_data(cqe) == NULL) {
  123. if (i < nr) {
  124. fprintf(stderr, "%s: timeout received too early\n", __FUNCTION__);
  125. goto err;
  126. }
  127. if (ret) {
  128. fprintf(stderr, "%s: timeout triggered by passage of"
  129. " time, not by events completed\n", __FUNCTION__);
  130. goto err;
  131. }
  132. }
  133. io_uring_cqe_seen(ring, cqe);
  134. if (ret) {
  135. fprintf(stderr, "res: %d\n", ret);
  136. goto err;
  137. }
  138. i++;
  139. }
  140. return 0;
  141. err:
  142. return 1;
  143. }
  144. static int test_single_timeout_wait(struct io_uring *ring,
  145. struct io_uring_params *p)
  146. {
  147. struct io_uring_cqe *cqe;
  148. struct io_uring_sqe *sqe;
  149. struct __kernel_timespec ts;
  150. int i, ret;
  151. sqe = io_uring_get_sqe(ring);
  152. io_uring_prep_nop(sqe);
  153. io_uring_sqe_set_data(sqe, (void *) 1);
  154. sqe = io_uring_get_sqe(ring);
  155. io_uring_prep_nop(sqe);
  156. io_uring_sqe_set_data(sqe, (void *) 1);
  157. /* no implied submit for newer kernels */
  158. if (p->features & IORING_FEAT_EXT_ARG) {
  159. ret = io_uring_submit(ring);
  160. if (ret != 2) {
  161. fprintf(stderr, "%s: submit %d\n", __FUNCTION__, ret);
  162. return 1;
  163. }
  164. }
  165. msec_to_ts(&ts, 1000);
  166. i = 0;
  167. do {
  168. ret = io_uring_wait_cqes(ring, &cqe, 2, &ts, NULL);
  169. if (ret == -ETIME)
  170. break;
  171. if (ret < 0) {
  172. fprintf(stderr, "%s: wait timeout failed: %d\n", __FUNCTION__, ret);
  173. goto err;
  174. }
  175. ret = cqe->res;
  176. io_uring_cqe_seen(ring, cqe);
  177. if (ret < 0) {
  178. fprintf(stderr, "res: %d\n", ret);
  179. goto err;
  180. }
  181. i++;
  182. } while (1);
  183. if (i != 2) {
  184. fprintf(stderr, "got %d completions\n", i);
  185. goto err;
  186. }
  187. return 0;
  188. err:
  189. return 1;
  190. }
  191. /*
  192. * Test single timeout waking us up
  193. */
  194. static int test_single_timeout(struct io_uring *ring)
  195. {
  196. struct io_uring_cqe *cqe;
  197. struct io_uring_sqe *sqe;
  198. unsigned long long exp;
  199. struct __kernel_timespec ts;
  200. struct timeval tv;
  201. int ret;
  202. sqe = io_uring_get_sqe(ring);
  203. if (!sqe) {
  204. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  205. goto err;
  206. }
  207. msec_to_ts(&ts, TIMEOUT_MSEC);
  208. io_uring_prep_timeout(sqe, &ts, 0, 0);
  209. ret = io_uring_submit(ring);
  210. if (ret <= 0) {
  211. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  212. goto err;
  213. }
  214. gettimeofday(&tv, NULL);
  215. ret = io_uring_wait_cqe(ring, &cqe);
  216. if (ret < 0) {
  217. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  218. goto err;
  219. }
  220. ret = cqe->res;
  221. io_uring_cqe_seen(ring, cqe);
  222. if (ret == -EINVAL) {
  223. fprintf(stdout, "%s: Timeout not supported, ignored\n", __FUNCTION__);
  224. not_supported = 1;
  225. return 0;
  226. } else if (ret != -ETIME) {
  227. fprintf(stderr, "%s: Timeout: %s\n", __FUNCTION__, strerror(-ret));
  228. goto err;
  229. }
  230. exp = mtime_since_now(&tv);
  231. if (exp >= TIMEOUT_MSEC / 2 && exp <= (TIMEOUT_MSEC * 3) / 2)
  232. return 0;
  233. fprintf(stderr, "%s: Timeout seems wonky (got %llu)\n", __FUNCTION__, exp);
  234. err:
  235. return 1;
  236. }
  237. static int test_single_timeout_remove_notfound(struct io_uring *ring)
  238. {
  239. struct io_uring_cqe *cqe;
  240. struct io_uring_sqe *sqe;
  241. struct __kernel_timespec ts;
  242. int ret, i;
  243. if (no_modify)
  244. return 0;
  245. sqe = io_uring_get_sqe(ring);
  246. if (!sqe) {
  247. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  248. goto err;
  249. }
  250. msec_to_ts(&ts, TIMEOUT_MSEC);
  251. io_uring_prep_timeout(sqe, &ts, 2, 0);
  252. sqe->user_data = 1;
  253. ret = io_uring_submit(ring);
  254. if (ret <= 0) {
  255. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  256. goto err;
  257. }
  258. sqe = io_uring_get_sqe(ring);
  259. if (!sqe) {
  260. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  261. goto err;
  262. }
  263. io_uring_prep_timeout_remove(sqe, 2, 0);
  264. sqe->user_data = 2;
  265. ret = io_uring_submit(ring);
  266. if (ret <= 0) {
  267. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  268. goto err;
  269. }
  270. /*
  271. * We should get two completions. One is our modify request, which should
  272. * complete with -ENOENT. The other is the timeout that will trigger after
  273. * TIMEOUT_MSEC.
  274. */
  275. for (i = 0; i < 2; i++) {
  276. ret = io_uring_wait_cqe(ring, &cqe);
  277. if (ret < 0) {
  278. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  279. goto err;
  280. }
  281. if (cqe->user_data == 2) {
  282. if (cqe->res != -ENOENT) {
  283. fprintf(stderr, "%s: modify ret %d, wanted ENOENT\n", __FUNCTION__, cqe->res);
  284. break;
  285. }
  286. } else if (cqe->user_data == 1) {
  287. if (cqe->res != -ETIME) {
  288. fprintf(stderr, "%s: timeout ret %d, wanted -ETIME\n", __FUNCTION__, cqe->res);
  289. break;
  290. }
  291. }
  292. io_uring_cqe_seen(ring, cqe);
  293. }
  294. return 0;
  295. err:
  296. return 1;
  297. }
  298. static int test_single_timeout_remove(struct io_uring *ring)
  299. {
  300. struct io_uring_cqe *cqe;
  301. struct io_uring_sqe *sqe;
  302. struct __kernel_timespec ts;
  303. int ret, i;
  304. sqe = io_uring_get_sqe(ring);
  305. if (!sqe) {
  306. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  307. goto err;
  308. }
  309. msec_to_ts(&ts, TIMEOUT_MSEC);
  310. io_uring_prep_timeout(sqe, &ts, 0, 0);
  311. sqe->user_data = 1;
  312. ret = io_uring_submit(ring);
  313. if (ret <= 0) {
  314. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  315. goto err;
  316. }
  317. sqe = io_uring_get_sqe(ring);
  318. if (!sqe) {
  319. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  320. goto err;
  321. }
  322. io_uring_prep_timeout_remove(sqe, 1, 0);
  323. sqe->user_data = 2;
  324. ret = io_uring_submit(ring);
  325. if (ret <= 0) {
  326. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  327. goto err;
  328. }
  329. /*
  330. * We should have two completions ready. One is for the original timeout
  331. * request, user_data == 1, that should have a ret of -ECANCELED. The other
  332. * is for our modify request, user_data == 2, that should have a ret of 0.
  333. */
  334. for (i = 0; i < 2; i++) {
  335. ret = io_uring_wait_cqe(ring, &cqe);
  336. if (ret < 0) {
  337. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  338. goto err;
  339. }
  340. if (no_modify)
  341. goto seen;
  342. if (cqe->res == -EINVAL && cqe->user_data == 2) {
  343. fprintf(stdout, "Timeout modify not supported, ignoring\n");
  344. no_modify = 1;
  345. goto seen;
  346. }
  347. if (cqe->user_data == 1) {
  348. if (cqe->res != -ECANCELED) {
  349. fprintf(stderr, "%s: timeout ret %d, wanted canceled\n", __FUNCTION__, cqe->res);
  350. break;
  351. }
  352. } else if (cqe->user_data == 2) {
  353. if (cqe->res) {
  354. fprintf(stderr, "%s: modify ret %d, wanted 0\n", __FUNCTION__, cqe->res);
  355. break;
  356. }
  357. }
  358. seen:
  359. io_uring_cqe_seen(ring, cqe);
  360. }
  361. return 0;
  362. err:
  363. return 1;
  364. }
  365. /*
  366. * Test single absolute timeout waking us up
  367. */
  368. static int test_single_timeout_abs(struct io_uring *ring)
  369. {
  370. struct io_uring_cqe *cqe;
  371. struct io_uring_sqe *sqe;
  372. unsigned long long exp;
  373. struct __kernel_timespec ts;
  374. struct timespec abs_ts;
  375. struct timeval tv;
  376. int ret;
  377. sqe = io_uring_get_sqe(ring);
  378. if (!sqe) {
  379. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  380. goto err;
  381. }
  382. clock_gettime(CLOCK_MONOTONIC, &abs_ts);
  383. ts.tv_sec = abs_ts.tv_sec + 1;
  384. ts.tv_nsec = abs_ts.tv_nsec;
  385. io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_ABS);
  386. ret = io_uring_submit(ring);
  387. if (ret <= 0) {
  388. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  389. goto err;
  390. }
  391. gettimeofday(&tv, NULL);
  392. ret = io_uring_wait_cqe(ring, &cqe);
  393. if (ret < 0) {
  394. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  395. goto err;
  396. }
  397. ret = cqe->res;
  398. io_uring_cqe_seen(ring, cqe);
  399. if (ret == -EINVAL) {
  400. fprintf(stdout, "Absolute timeouts not supported, ignored\n");
  401. return 0;
  402. } else if (ret != -ETIME) {
  403. fprintf(stderr, "Timeout: %s\n", strerror(-ret));
  404. goto err;
  405. }
  406. exp = mtime_since_now(&tv);
  407. if (exp >= 1000 / 2 && exp <= (1000 * 3) / 2)
  408. return 0;
  409. fprintf(stderr, "%s: Timeout seems wonky (got %llu)\n", __FUNCTION__, exp);
  410. err:
  411. return 1;
  412. }
  413. /*
  414. * Test that timeout is canceled on exit
  415. */
  416. static int test_single_timeout_exit(struct io_uring *ring)
  417. {
  418. struct io_uring_sqe *sqe;
  419. struct __kernel_timespec ts;
  420. int ret;
  421. sqe = io_uring_get_sqe(ring);
  422. if (!sqe) {
  423. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  424. goto err;
  425. }
  426. msec_to_ts(&ts, 30000);
  427. io_uring_prep_timeout(sqe, &ts, 0, 0);
  428. ret = io_uring_submit(ring);
  429. if (ret <= 0) {
  430. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  431. goto err;
  432. }
  433. io_uring_queue_exit(ring);
  434. return 0;
  435. err:
  436. io_uring_queue_exit(ring);
  437. return 1;
  438. }
  439. /*
  440. * Test multi timeouts waking us up
  441. */
  442. static int test_multi_timeout(struct io_uring *ring)
  443. {
  444. struct io_uring_sqe *sqe;
  445. struct io_uring_cqe *cqe;
  446. struct __kernel_timespec ts[2];
  447. unsigned int timeout[2];
  448. unsigned long long exp;
  449. struct timeval tv;
  450. int ret, i;
  451. /* req_1: timeout req, count = 1, time = (TIMEOUT_MSEC * 2) */
  452. timeout[0] = TIMEOUT_MSEC * 2;
  453. msec_to_ts(&ts[0], timeout[0]);
  454. sqe = io_uring_get_sqe(ring);
  455. if (!sqe) {
  456. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  457. goto err;
  458. }
  459. io_uring_prep_timeout(sqe, &ts[0], 1, 0);
  460. sqe->user_data = 1;
  461. /* req_2: timeout req, count = 1, time = TIMEOUT_MSEC */
  462. timeout[1] = TIMEOUT_MSEC;
  463. msec_to_ts(&ts[1], timeout[1]);
  464. sqe = io_uring_get_sqe(ring);
  465. if (!sqe) {
  466. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  467. goto err;
  468. }
  469. io_uring_prep_timeout(sqe, &ts[1], 1, 0);
  470. sqe->user_data = 2;
  471. ret = io_uring_submit(ring);
  472. if (ret <= 0) {
  473. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  474. goto err;
  475. }
  476. gettimeofday(&tv, NULL);
  477. for (i = 0; i < 2; i++) {
  478. unsigned int time = 0;
  479. __u64 user_data = 0;
  480. ret = io_uring_wait_cqe(ring, &cqe);
  481. if (ret < 0) {
  482. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  483. goto err;
  484. }
  485. /*
  486. * Both of these two reqs should timeout, but req_2 should
  487. * return before req_1.
  488. */
  489. switch (i) {
  490. case 0:
  491. user_data = 2;
  492. time = timeout[1];
  493. break;
  494. case 1:
  495. user_data = 1;
  496. time = timeout[0];
  497. break;
  498. }
  499. if (cqe->user_data != user_data) {
  500. fprintf(stderr, "%s: unexpected timeout req %d sequence\n",
  501. __FUNCTION__, i+1);
  502. goto err;
  503. }
  504. if (cqe->res != -ETIME) {
  505. fprintf(stderr, "%s: Req %d timeout: %s\n",
  506. __FUNCTION__, i+1, strerror(cqe->res));
  507. goto err;
  508. }
  509. exp = mtime_since_now(&tv);
  510. if (exp < time / 2 || exp > (time * 3) / 2) {
  511. fprintf(stderr, "%s: Req %d timeout seems wonky (got %llu)\n",
  512. __FUNCTION__, i+1, exp);
  513. goto err;
  514. }
  515. io_uring_cqe_seen(ring, cqe);
  516. }
  517. return 0;
  518. err:
  519. return 1;
  520. }
  521. /*
  522. * Test multi timeout req with different count
  523. */
  524. static int test_multi_timeout_nr(struct io_uring *ring)
  525. {
  526. struct io_uring_sqe *sqe;
  527. struct io_uring_cqe *cqe;
  528. struct __kernel_timespec ts;
  529. int ret, i;
  530. msec_to_ts(&ts, TIMEOUT_MSEC);
  531. /* req_1: timeout req, count = 2 */
  532. sqe = io_uring_get_sqe(ring);
  533. if (!sqe) {
  534. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  535. goto err;
  536. }
  537. io_uring_prep_timeout(sqe, &ts, 2, 0);
  538. sqe->user_data = 1;
  539. /* req_2: timeout req, count = 1 */
  540. sqe = io_uring_get_sqe(ring);
  541. if (!sqe) {
  542. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  543. goto err;
  544. }
  545. io_uring_prep_timeout(sqe, &ts, 1, 0);
  546. sqe->user_data = 2;
  547. /* req_3: nop req */
  548. sqe = io_uring_get_sqe(ring);
  549. if (!sqe) {
  550. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  551. goto err;
  552. }
  553. io_uring_prep_nop(sqe);
  554. io_uring_sqe_set_data(sqe, (void *) 1);
  555. ret = io_uring_submit(ring);
  556. if (ret <= 0) {
  557. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  558. goto err;
  559. }
  560. /*
  561. * req_2 (count=1) should return without error and req_1 (count=2)
  562. * should timeout.
  563. */
  564. for (i = 0; i < 3; i++) {
  565. ret = io_uring_wait_cqe(ring, &cqe);
  566. if (ret < 0) {
  567. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  568. goto err;
  569. }
  570. switch (i) {
  571. case 0:
  572. /* Should be nop req */
  573. if (io_uring_cqe_get_data(cqe) != (void *) 1) {
  574. fprintf(stderr, "%s: nop not seen as 1 or 2\n", __FUNCTION__);
  575. goto err;
  576. }
  577. break;
  578. case 1:
  579. /* Should be timeout req_2 */
  580. if (cqe->user_data != 2) {
  581. fprintf(stderr, "%s: unexpected timeout req %d sequence\n",
  582. __FUNCTION__, i+1);
  583. goto err;
  584. }
  585. if (cqe->res < 0) {
  586. fprintf(stderr, "%s: Req %d res %d\n",
  587. __FUNCTION__, i+1, cqe->res);
  588. goto err;
  589. }
  590. break;
  591. case 2:
  592. /* Should be timeout req_1 */
  593. if (cqe->user_data != 1) {
  594. fprintf(stderr, "%s: unexpected timeout req %d sequence\n",
  595. __FUNCTION__, i+1);
  596. goto err;
  597. }
  598. if (cqe->res != -ETIME) {
  599. fprintf(stderr, "%s: Req %d timeout: %s\n",
  600. __FUNCTION__, i+1, strerror(cqe->res));
  601. goto err;
  602. }
  603. break;
  604. }
  605. io_uring_cqe_seen(ring, cqe);
  606. }
  607. return 0;
  608. err:
  609. return 1;
  610. }
  611. /*
  612. * Test timeout <link> timeout <drain> timeout
  613. */
  614. static int test_timeout_flags1(struct io_uring *ring)
  615. {
  616. struct io_uring_sqe *sqe;
  617. struct io_uring_cqe *cqe;
  618. struct __kernel_timespec ts;
  619. int ret, i;
  620. msec_to_ts(&ts, TIMEOUT_MSEC);
  621. sqe = io_uring_get_sqe(ring);
  622. if (!sqe) {
  623. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  624. goto err;
  625. }
  626. io_uring_prep_timeout(sqe, &ts, 0, 0);
  627. sqe->user_data = 1;
  628. sqe->flags |= IOSQE_IO_LINK;
  629. sqe = io_uring_get_sqe(ring);
  630. if (!sqe) {
  631. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  632. goto err;
  633. }
  634. io_uring_prep_timeout(sqe, &ts, 0, 0);
  635. sqe->user_data = 2;
  636. sqe->flags |= IOSQE_IO_DRAIN;
  637. sqe = io_uring_get_sqe(ring);
  638. if (!sqe) {
  639. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  640. goto err;
  641. }
  642. io_uring_prep_timeout(sqe, &ts, 0, 0);
  643. sqe->user_data = 3;
  644. ret = io_uring_submit(ring);
  645. if (ret <= 0) {
  646. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  647. goto err;
  648. }
  649. for (i = 0; i < 3; i++) {
  650. ret = io_uring_wait_cqe(ring, &cqe);
  651. if (ret < 0) {
  652. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  653. goto err;
  654. }
  655. if (cqe->res == -EINVAL) {
  656. if (!i)
  657. fprintf(stdout, "%s: timeout flags not supported\n",
  658. __FUNCTION__);
  659. io_uring_cqe_seen(ring, cqe);
  660. continue;
  661. }
  662. switch (cqe->user_data) {
  663. case 1:
  664. if (cqe->res != -ETIME) {
  665. fprintf(stderr, "%s: got %d, wanted %d\n",
  666. __FUNCTION__, cqe->res, -ETIME);
  667. goto err;
  668. }
  669. break;
  670. case 2:
  671. if (cqe->res != -ECANCELED) {
  672. fprintf(stderr, "%s: got %d, wanted %d\n",
  673. __FUNCTION__, cqe->res,
  674. -ECANCELED);
  675. goto err;
  676. }
  677. break;
  678. case 3:
  679. if (cqe->res != -ETIME) {
  680. fprintf(stderr, "%s: got %d, wanted %d\n",
  681. __FUNCTION__, cqe->res, -ETIME);
  682. goto err;
  683. }
  684. break;
  685. }
  686. io_uring_cqe_seen(ring, cqe);
  687. }
  688. return 0;
  689. err:
  690. return 1;
  691. }
  692. /*
  693. * Test timeout <link> timeout <link> timeout
  694. */
  695. static int test_timeout_flags2(struct io_uring *ring)
  696. {
  697. struct io_uring_sqe *sqe;
  698. struct io_uring_cqe *cqe;
  699. struct __kernel_timespec ts;
  700. int ret, i;
  701. msec_to_ts(&ts, TIMEOUT_MSEC);
  702. sqe = io_uring_get_sqe(ring);
  703. if (!sqe) {
  704. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  705. goto err;
  706. }
  707. io_uring_prep_timeout(sqe, &ts, 0, 0);
  708. sqe->user_data = 1;
  709. sqe->flags |= IOSQE_IO_LINK;
  710. sqe = io_uring_get_sqe(ring);
  711. if (!sqe) {
  712. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  713. goto err;
  714. }
  715. io_uring_prep_timeout(sqe, &ts, 0, 0);
  716. sqe->user_data = 2;
  717. sqe->flags |= IOSQE_IO_LINK;
  718. sqe = io_uring_get_sqe(ring);
  719. if (!sqe) {
  720. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  721. goto err;
  722. }
  723. io_uring_prep_timeout(sqe, &ts, 0, 0);
  724. sqe->user_data = 3;
  725. ret = io_uring_submit(ring);
  726. if (ret <= 0) {
  727. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  728. goto err;
  729. }
  730. for (i = 0; i < 3; i++) {
  731. ret = io_uring_wait_cqe(ring, &cqe);
  732. if (ret < 0) {
  733. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  734. goto err;
  735. }
  736. if (cqe->res == -EINVAL) {
  737. if (!i)
  738. fprintf(stdout, "%s: timeout flags not supported\n",
  739. __FUNCTION__);
  740. io_uring_cqe_seen(ring, cqe);
  741. continue;
  742. }
  743. switch (cqe->user_data) {
  744. case 1:
  745. if (cqe->res != -ETIME) {
  746. fprintf(stderr, "%s: got %d, wanted %d\n",
  747. __FUNCTION__, cqe->res, -ETIME);
  748. goto err;
  749. }
  750. break;
  751. case 2:
  752. case 3:
  753. if (cqe->res != -ECANCELED) {
  754. fprintf(stderr, "%s: got %d, wanted %d\n",
  755. __FUNCTION__, cqe->res,
  756. -ECANCELED);
  757. goto err;
  758. }
  759. break;
  760. }
  761. io_uring_cqe_seen(ring, cqe);
  762. }
  763. return 0;
  764. err:
  765. return 1;
  766. }
  767. /*
  768. * Test timeout <drain> timeout <link> timeout
  769. */
  770. static int test_timeout_flags3(struct io_uring *ring)
  771. {
  772. struct io_uring_sqe *sqe;
  773. struct io_uring_cqe *cqe;
  774. struct __kernel_timespec ts;
  775. int ret, i;
  776. msec_to_ts(&ts, TIMEOUT_MSEC);
  777. sqe = io_uring_get_sqe(ring);
  778. if (!sqe) {
  779. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  780. goto err;
  781. }
  782. io_uring_prep_timeout(sqe, &ts, 0, 0);
  783. sqe->user_data = 1;
  784. sqe->flags |= IOSQE_IO_DRAIN;
  785. sqe = io_uring_get_sqe(ring);
  786. if (!sqe) {
  787. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  788. goto err;
  789. }
  790. io_uring_prep_timeout(sqe, &ts, 0, 0);
  791. sqe->user_data = 2;
  792. sqe->flags |= IOSQE_IO_LINK;
  793. sqe = io_uring_get_sqe(ring);
  794. if (!sqe) {
  795. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  796. goto err;
  797. }
  798. io_uring_prep_timeout(sqe, &ts, 0, 0);
  799. sqe->user_data = 3;
  800. ret = io_uring_submit(ring);
  801. if (ret <= 0) {
  802. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  803. goto err;
  804. }
  805. for (i = 0; i < 3; i++) {
  806. ret = io_uring_wait_cqe(ring, &cqe);
  807. if (ret < 0) {
  808. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  809. goto err;
  810. }
  811. if (cqe->res == -EINVAL) {
  812. if (!i)
  813. fprintf(stdout, "%s: timeout flags not supported\n",
  814. __FUNCTION__);
  815. io_uring_cqe_seen(ring, cqe);
  816. continue;
  817. }
  818. switch (cqe->user_data) {
  819. case 1:
  820. case 2:
  821. if (cqe->res != -ETIME) {
  822. fprintf(stderr, "%s: got %d, wanted %d\n",
  823. __FUNCTION__, cqe->res, -ETIME);
  824. goto err;
  825. }
  826. break;
  827. case 3:
  828. if (cqe->res != -ECANCELED) {
  829. fprintf(stderr, "%s: got %d, wanted %d\n",
  830. __FUNCTION__, cqe->res,
  831. -ECANCELED);
  832. goto err;
  833. }
  834. break;
  835. }
  836. io_uring_cqe_seen(ring, cqe);
  837. }
  838. return 0;
  839. err:
  840. return 1;
  841. }
  842. static int test_update_timeout(struct io_uring *ring, unsigned long ms,
  843. bool abs, bool async, bool linked)
  844. {
  845. struct io_uring_sqe *sqe;
  846. struct io_uring_cqe *cqe;
  847. struct __kernel_timespec ts, ts_upd;
  848. unsigned long long exp_ms, base_ms = 10000;
  849. bool update_ealready = false;
  850. struct timeval tv;
  851. int ret, i, nr = 2;
  852. __u32 mode = abs ? IORING_TIMEOUT_ABS : 0;
  853. msec_to_ts(&ts_upd, ms);
  854. gettimeofday(&tv, NULL);
  855. sqe = io_uring_get_sqe(ring);
  856. if (!sqe) {
  857. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  858. goto err;
  859. }
  860. msec_to_ts(&ts, base_ms);
  861. io_uring_prep_timeout(sqe, &ts, 0, 0);
  862. sqe->user_data = 1;
  863. if (linked) {
  864. sqe = io_uring_get_sqe(ring);
  865. if (!sqe) {
  866. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  867. goto err;
  868. }
  869. io_uring_prep_nop(sqe);
  870. sqe->user_data = 3;
  871. sqe->flags = IOSQE_IO_LINK;
  872. if (async)
  873. sqe->flags |= IOSQE_ASYNC;
  874. nr++;
  875. }
  876. sqe = io_uring_get_sqe(ring);
  877. if (!sqe) {
  878. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  879. goto err;
  880. }
  881. io_uring_prep_timeout_update(sqe, &ts_upd, 1, mode);
  882. sqe->user_data = 2;
  883. if (async)
  884. sqe->flags |= IOSQE_ASYNC;
  885. ret = io_uring_submit(ring);
  886. if (ret != nr) {
  887. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  888. goto err;
  889. }
  890. for (i = 0; i < nr; i++) {
  891. ret = io_uring_wait_cqe(ring, &cqe);
  892. if (ret < 0) {
  893. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  894. goto err;
  895. }
  896. switch (cqe->user_data) {
  897. case 1:
  898. if (cqe->res != -ETIME) {
  899. fprintf(stderr, "%s: got %d, wanted %d\n",
  900. __FUNCTION__, cqe->res, -ETIME);
  901. goto err;
  902. }
  903. break;
  904. case 2:
  905. /*
  906. * We should not be hitting this case, but for
  907. * a kernel with PREEMPT_RT, even an instant attempt
  908. * to remove a timer will return that the timer is
  909. * already running... Deal with it.
  910. */
  911. if (cqe->res == -EALREADY) {
  912. update_ealready = true;
  913. break;
  914. }
  915. if (cqe->res != 0) {
  916. fprintf(stderr, "%s: got %d, wanted %d\n",
  917. __FUNCTION__, cqe->res,
  918. 0);
  919. goto err;
  920. }
  921. break;
  922. case 3:
  923. if (cqe->res != 0) {
  924. fprintf(stderr, "nop failed\n");
  925. goto err;
  926. }
  927. break;
  928. default:
  929. goto err;
  930. }
  931. io_uring_cqe_seen(ring, cqe);
  932. }
  933. exp_ms = mtime_since_now(&tv);
  934. if (!update_ealready && exp_ms >= base_ms / 2) {
  935. fprintf(stderr, "too long, timeout wasn't updated\n");
  936. goto err;
  937. }
  938. if (ms >= 1000 && !abs && exp_ms < ms / 2) {
  939. fprintf(stderr, "fired too early, potentially updated to 0 ms"
  940. "instead of %lu\n", ms);
  941. goto err;
  942. }
  943. return 0;
  944. err:
  945. return 1;
  946. }
  947. static int test_update_multishot_timeouts(struct io_uring *ring, unsigned long ms)
  948. {
  949. struct io_uring_sqe *sqe;
  950. struct io_uring_cqe *cqe;
  951. struct __kernel_timespec ts, ts_upd;
  952. unsigned long long exp_ms, base_ms = 10000;
  953. struct timeval tv1, tv2;
  954. int ret, i, nr = 6;
  955. __u32 mode = 0;
  956. msec_to_ts(&ts, base_ms);
  957. msec_to_ts(&ts_upd, ms);
  958. gettimeofday(&tv1, NULL);
  959. gettimeofday(&tv2, NULL);
  960. sqe = io_uring_get_sqe(ring);
  961. if (!sqe) {
  962. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  963. goto err;
  964. }
  965. msec_to_ts(&ts, base_ms);
  966. io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_MULTISHOT);
  967. sqe->user_data = 1;
  968. sqe = io_uring_get_sqe(ring);
  969. if (!sqe) {
  970. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  971. goto err;
  972. }
  973. io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_MULTISHOT);
  974. sqe->user_data = 2;
  975. sqe = io_uring_get_sqe(ring);
  976. if (!sqe) {
  977. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  978. goto err;
  979. }
  980. io_uring_prep_timeout_update(sqe, &ts_upd, 1, mode);
  981. sqe->user_data = 3;
  982. sqe = io_uring_get_sqe(ring);
  983. if (!sqe) {
  984. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  985. goto err;
  986. }
  987. io_uring_prep_timeout_update(sqe, &ts_upd, 2, mode);
  988. sqe->user_data = 4;
  989. ret = io_uring_submit(ring);
  990. if (ret == 0) {
  991. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  992. goto err;
  993. }
  994. for (i = 0; i < nr; i++) {
  995. ret = io_uring_wait_cqe(ring, &cqe);
  996. if (ret < 0) {
  997. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  998. goto err;
  999. }
  1000. switch (cqe->user_data) {
  1001. case 1:
  1002. if (cqe->res != -ETIME) {
  1003. fprintf(stderr, "%s: got %d, wanted %d\n",
  1004. __FUNCTION__, cqe->res, -ETIME);
  1005. goto err;
  1006. }
  1007. exp_ms = mtime_since_now(&tv1);
  1008. if (exp_ms > 1.05 * ms) {
  1009. fprintf(stderr, "too long, timeout wasn't updated (expired after %llu instead of %lu)\n", exp_ms, ms);
  1010. goto err;
  1011. }
  1012. gettimeofday(&tv1, NULL);
  1013. break;
  1014. case 2:
  1015. if (cqe->res != -ETIME) {
  1016. fprintf(stderr, "%s: got %d, wanted %d\n",
  1017. __FUNCTION__, cqe->res, -ETIME);
  1018. goto err;
  1019. }
  1020. exp_ms = mtime_since_now(&tv2);
  1021. if (exp_ms > 1.05 * ms) {
  1022. fprintf(stderr, "too long, timeout wasn't updated (expired after %llu instead of %lu)\n", exp_ms, ms);
  1023. goto err;
  1024. }
  1025. gettimeofday(&tv2, NULL);
  1026. break;
  1027. case 3:
  1028. case 4:
  1029. if (cqe->res != 0) {
  1030. fprintf(stderr, "%s: got %d, wanted %d\n",
  1031. __FUNCTION__, cqe->res, 0);
  1032. goto err;
  1033. }
  1034. break;
  1035. default:
  1036. goto err;
  1037. }
  1038. io_uring_cqe_seen(ring, cqe);
  1039. }
  1040. sqe = io_uring_get_sqe(ring);
  1041. if (!sqe) {
  1042. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  1043. goto err;
  1044. }
  1045. io_uring_prep_timeout_remove(sqe, 1, 0);
  1046. sqe = io_uring_get_sqe(ring);
  1047. if (!sqe) {
  1048. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  1049. goto err;
  1050. }
  1051. io_uring_prep_timeout_remove(sqe, 2, 0);
  1052. ret = io_uring_submit(ring);
  1053. if (ret != 2) {
  1054. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  1055. goto err;
  1056. }
  1057. for (i = 0; i < 2; i++) {
  1058. ret = io_uring_wait_cqe(ring, &cqe);
  1059. if (ret < 0) {
  1060. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1061. goto err;
  1062. }
  1063. io_uring_cqe_seen(ring, cqe);
  1064. }
  1065. return 0;
  1066. err:
  1067. return 1;
  1068. }
  1069. static int test_update_nonexistent_timeout(struct io_uring *ring)
  1070. {
  1071. struct io_uring_sqe *sqe;
  1072. struct io_uring_cqe *cqe;
  1073. struct __kernel_timespec ts;
  1074. int ret;
  1075. sqe = io_uring_get_sqe(ring);
  1076. if (!sqe) {
  1077. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  1078. goto err;
  1079. }
  1080. msec_to_ts(&ts, 0);
  1081. io_uring_prep_timeout_update(sqe, &ts, 42, 0);
  1082. ret = io_uring_submit(ring);
  1083. if (ret != 1) {
  1084. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  1085. goto err;
  1086. }
  1087. ret = io_uring_wait_cqe(ring, &cqe);
  1088. if (ret < 0) {
  1089. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1090. goto err;
  1091. }
  1092. ret = cqe->res;
  1093. if (ret == -ENOENT)
  1094. ret = 0;
  1095. io_uring_cqe_seen(ring, cqe);
  1096. return ret;
  1097. err:
  1098. return 1;
  1099. }
  1100. static int test_update_invalid_flags(struct io_uring *ring)
  1101. {
  1102. struct io_uring_sqe *sqe;
  1103. struct io_uring_cqe *cqe;
  1104. struct __kernel_timespec ts;
  1105. int ret;
  1106. sqe = io_uring_get_sqe(ring);
  1107. if (!sqe) {
  1108. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  1109. goto err;
  1110. }
  1111. io_uring_prep_timeout_remove(sqe, 0, IORING_TIMEOUT_ABS);
  1112. ret = io_uring_submit(ring);
  1113. if (ret != 1) {
  1114. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  1115. goto err;
  1116. }
  1117. ret = io_uring_wait_cqe(ring, &cqe);
  1118. if (ret < 0) {
  1119. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1120. goto err;
  1121. }
  1122. if (cqe->res != -EINVAL) {
  1123. fprintf(stderr, "%s: got %d, wanted %d\n",
  1124. __FUNCTION__, cqe->res, -EINVAL);
  1125. goto err;
  1126. }
  1127. io_uring_cqe_seen(ring, cqe);
  1128. sqe = io_uring_get_sqe(ring);
  1129. if (!sqe) {
  1130. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  1131. goto err;
  1132. }
  1133. msec_to_ts(&ts, 0);
  1134. io_uring_prep_timeout_update(sqe, &ts, 0, -1);
  1135. ret = io_uring_submit(ring);
  1136. if (ret != 1) {
  1137. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  1138. goto err;
  1139. }
  1140. ret = io_uring_wait_cqe(ring, &cqe);
  1141. if (ret < 0) {
  1142. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1143. goto err;
  1144. }
  1145. if (cqe->res != -EINVAL) {
  1146. fprintf(stderr, "%s: got %d, wanted %d\n",
  1147. __FUNCTION__, cqe->res, -EINVAL);
  1148. goto err;
  1149. }
  1150. io_uring_cqe_seen(ring, cqe);
  1151. return 0;
  1152. err:
  1153. return 1;
  1154. }
  1155. static int fill_exec_target(char *dst, char *path)
  1156. {
  1157. struct stat sb;
  1158. /*
  1159. * Should either be ./exec-target.t or test/exec-target.t
  1160. */
  1161. sprintf(dst, "%s", path);
  1162. return stat(dst, &sb);
  1163. }
  1164. static int test_timeout_link_cancel(void)
  1165. {
  1166. struct io_uring ring;
  1167. struct io_uring_cqe *cqe;
  1168. char prog_path[PATH_MAX];
  1169. pid_t p;
  1170. int ret, i, wstatus;
  1171. if (fill_exec_target(prog_path, "./exec-target.t") &&
  1172. fill_exec_target(prog_path, "test/exec-target.t")) {
  1173. fprintf(stdout, "Can't find exec-target, skipping\n");
  1174. return 0;
  1175. }
  1176. ret = io_uring_queue_init(8, &ring, 0);
  1177. if (ret) {
  1178. fprintf(stderr, "ring create failed: %d\n", ret);
  1179. return 1;
  1180. }
  1181. p = fork();
  1182. if (p == -1) {
  1183. fprintf(stderr, "fork() failed\n");
  1184. return 1;
  1185. }
  1186. if (p == 0) {
  1187. struct io_uring_sqe *sqe;
  1188. struct __kernel_timespec ts;
  1189. msec_to_ts(&ts, 10000);
  1190. sqe = io_uring_get_sqe(&ring);
  1191. io_uring_prep_timeout(sqe, &ts, 0, 0);
  1192. sqe->flags |= IOSQE_IO_LINK;
  1193. sqe->user_data = 0;
  1194. sqe = io_uring_get_sqe(&ring);
  1195. io_uring_prep_nop(sqe);
  1196. sqe->user_data = 1;
  1197. ret = io_uring_submit(&ring);
  1198. if (ret != 2) {
  1199. fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
  1200. exit(1);
  1201. }
  1202. /* trigger full cancelation */
  1203. ret = execl(prog_path, prog_path, NULL);
  1204. if (ret) {
  1205. fprintf(stderr, "exec failed %i\n", errno);
  1206. exit(1);
  1207. }
  1208. exit(0);
  1209. }
  1210. do {
  1211. if (waitpid(p, &wstatus, 0) == (pid_t)-1) {
  1212. perror("waitpid()");
  1213. return 1;
  1214. }
  1215. if (!WIFEXITED(wstatus))
  1216. continue;
  1217. if (WEXITSTATUS(wstatus)) {
  1218. fprintf(stderr, "child failed %i\n", WEXITSTATUS(wstatus));
  1219. return 1;
  1220. }
  1221. break;
  1222. } while (1);
  1223. for (i = 0; i < 2; ++i) {
  1224. ret = io_uring_wait_cqe(&ring, &cqe);
  1225. if (ret) {
  1226. fprintf(stderr, "wait_cqe=%d\n", ret);
  1227. return 1;
  1228. }
  1229. if (cqe->res != -ECANCELED) {
  1230. fprintf(stderr, "invalid result, user_data: %i res: %i\n",
  1231. (int)cqe->user_data, cqe->res);
  1232. return 1;
  1233. }
  1234. io_uring_cqe_seen(&ring, cqe);
  1235. }
  1236. io_uring_queue_exit(&ring);
  1237. return 0;
  1238. }
  1239. static int test_not_failing_links(void)
  1240. {
  1241. struct io_uring ring;
  1242. struct io_uring_sqe *sqe;
  1243. struct io_uring_cqe *cqe;
  1244. struct __kernel_timespec ts;
  1245. int ret;
  1246. ret = io_uring_queue_init(8, &ring, 0);
  1247. if (ret) {
  1248. fprintf(stderr, "ring create failed: %d\n", ret);
  1249. return 1;
  1250. }
  1251. msec_to_ts(&ts, 1);
  1252. sqe = io_uring_get_sqe(&ring);
  1253. io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_ETIME_SUCCESS);
  1254. sqe->user_data = 1;
  1255. sqe->flags |= IOSQE_IO_LINK;
  1256. sqe = io_uring_get_sqe(&ring);
  1257. io_uring_prep_nop(sqe);
  1258. sqe->user_data = 2;
  1259. ret = io_uring_submit(&ring);
  1260. if (ret != 2) {
  1261. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  1262. return 1;
  1263. }
  1264. ret = io_uring_wait_cqe(&ring, &cqe);
  1265. if (ret < 0) {
  1266. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1267. return 1;
  1268. } else if (cqe->user_data == 1 && cqe->res == -EINVAL) {
  1269. goto done;
  1270. } else if (cqe->res != -ETIME || cqe->user_data != 1) {
  1271. fprintf(stderr, "timeout failed %i %i\n", cqe->res,
  1272. (int)cqe->user_data);
  1273. return 1;
  1274. }
  1275. io_uring_cqe_seen(&ring, cqe);
  1276. ret = io_uring_wait_cqe(&ring, &cqe);
  1277. if (ret < 0) {
  1278. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1279. return 1;
  1280. } else if (cqe->res || cqe->user_data != 2) {
  1281. fprintf(stderr, "nop failed %i %i\n", cqe->res,
  1282. (int)cqe->user_data);
  1283. return 1;
  1284. }
  1285. done:
  1286. io_uring_cqe_seen(&ring, cqe);
  1287. io_uring_queue_exit(&ring);
  1288. return 0;
  1289. }
  1290. static int test_timeout_multishot(struct io_uring *ring)
  1291. {
  1292. struct io_uring_cqe *cqe;
  1293. struct io_uring_sqe *sqe;
  1294. struct __kernel_timespec ts;
  1295. int ret;
  1296. sqe = io_uring_get_sqe(ring);
  1297. if (!sqe) {
  1298. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  1299. goto err;
  1300. }
  1301. msec_to_ts(&ts, TIMEOUT_MSEC);
  1302. io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_MULTISHOT);
  1303. io_uring_sqe_set_data(sqe, (void *) 1);
  1304. ret = io_uring_submit(ring);
  1305. if (ret <= 0) {
  1306. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  1307. goto err;
  1308. }
  1309. for (int i = 0; i < 2; i++) {
  1310. ret = io_uring_wait_cqe(ring, &cqe);
  1311. if (ret < 0) {
  1312. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1313. goto err;
  1314. }
  1315. ret = cqe->res;
  1316. if (ret == -EINVAL) {
  1317. no_multishot = 1;
  1318. return T_EXIT_SKIP;
  1319. }
  1320. if (!(cqe->flags & IORING_CQE_F_MORE)) {
  1321. fprintf(stderr, "%s: flag not set in cqe\n", __FUNCTION__);
  1322. goto err;
  1323. }
  1324. if (ret != -ETIME) {
  1325. fprintf(stderr, "%s: Timeout: %s\n", __FUNCTION__, strerror(-ret));
  1326. goto err;
  1327. }
  1328. io_uring_cqe_seen(ring, cqe);
  1329. }
  1330. sqe = io_uring_get_sqe(ring);
  1331. if (!sqe) {
  1332. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  1333. goto err;
  1334. }
  1335. io_uring_prep_timeout_remove(sqe, 1, 0);
  1336. io_uring_sqe_set_data(sqe, (void *) 2);
  1337. ret = io_uring_submit(ring);
  1338. if (ret <= 0) {
  1339. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  1340. goto err;
  1341. }
  1342. ret = io_uring_wait_cqe(ring, &cqe);
  1343. if (ret < 0) {
  1344. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1345. goto err;
  1346. }
  1347. ret = cqe->res;
  1348. if (ret < 0) {
  1349. fprintf(stderr, "%s: remove failed: %s\n", __FUNCTION__, strerror(-ret));
  1350. goto err;
  1351. }
  1352. io_uring_cqe_seen(ring, cqe);
  1353. ret = io_uring_wait_cqe(ring, &cqe);
  1354. if (ret < 0) {
  1355. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1356. goto err;
  1357. }
  1358. ret = cqe->res;
  1359. if (ret != -ECANCELED) {
  1360. fprintf(stderr, "%s: timeout canceled: %s %llu\n", __FUNCTION__, strerror(-ret), cqe->user_data);
  1361. goto err;
  1362. }
  1363. io_uring_cqe_seen(ring, cqe);
  1364. return 0;
  1365. err:
  1366. return 1;
  1367. }
  1368. static int test_timeout_multishot_nr(struct io_uring *ring)
  1369. {
  1370. struct io_uring_cqe *cqe;
  1371. struct io_uring_sqe *sqe;
  1372. struct __kernel_timespec ts;
  1373. int ret;
  1374. if (no_multishot)
  1375. return T_EXIT_SKIP;
  1376. sqe = io_uring_get_sqe(ring);
  1377. if (!sqe) {
  1378. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  1379. goto err;
  1380. }
  1381. msec_to_ts(&ts, TIMEOUT_MSEC);
  1382. io_uring_prep_timeout(sqe, &ts, 3, IORING_TIMEOUT_MULTISHOT);
  1383. io_uring_sqe_set_data(sqe, (void *) 1);
  1384. ret = io_uring_submit(ring);
  1385. if (ret <= 0) {
  1386. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  1387. goto err;
  1388. }
  1389. for (int i = 0; i < 3; i++) {
  1390. ret = io_uring_wait_cqe(ring, &cqe);
  1391. if (ret < 0) {
  1392. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1393. goto err;
  1394. }
  1395. if (i < 2 && !(cqe->flags & IORING_CQE_F_MORE)) {
  1396. fprintf(stderr, "%s: flag not set in cqe\n", __FUNCTION__);
  1397. goto err;
  1398. }
  1399. if (i == 3 && (cqe->flags & IORING_CQE_F_MORE)) {
  1400. fprintf(stderr, "%s: flag set in cqe\n", __FUNCTION__);
  1401. goto err;
  1402. }
  1403. ret = cqe->res;
  1404. if (ret != -ETIME) {
  1405. fprintf(stderr, "%s: Timeout: %s\n", __FUNCTION__, strerror(-ret));
  1406. goto err;
  1407. }
  1408. io_uring_cqe_seen(ring, cqe);
  1409. }
  1410. msec_to_ts(&ts, 2 * TIMEOUT_MSEC);
  1411. ret = io_uring_wait_cqe_timeout(ring, &cqe, &ts);
  1412. if (ret != -ETIME) {
  1413. fprintf(stderr, "%s: wait completion timeout %s\n", __FUNCTION__, strerror(-ret));
  1414. goto err;
  1415. }
  1416. return 0;
  1417. err:
  1418. return 1;
  1419. }
  1420. static int test_timeout_multishot_overflow(struct io_uring *ring)
  1421. {
  1422. struct io_uring_cqe *cqe;
  1423. struct io_uring_sqe *sqe;
  1424. struct __kernel_timespec ts;
  1425. int ret;
  1426. if (no_multishot)
  1427. return T_EXIT_SKIP;
  1428. sqe = io_uring_get_sqe(ring);
  1429. if (!sqe) {
  1430. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  1431. goto err;
  1432. }
  1433. msec_to_ts(&ts, 10);
  1434. io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_MULTISHOT);
  1435. io_uring_sqe_set_data(sqe, (void *) 1);
  1436. ret = io_uring_submit(ring);
  1437. if (ret <= 0) {
  1438. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  1439. goto err;
  1440. }
  1441. ret = io_uring_wait_cqe(ring, &cqe);
  1442. if (ret < 0) {
  1443. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1444. goto err;
  1445. }
  1446. ret = cqe->res;
  1447. if (ret != -ETIME) {
  1448. fprintf(stderr, "%s: Timeout: %s\n", __FUNCTION__, strerror(-ret));
  1449. goto err;
  1450. }
  1451. io_uring_cqe_seen(ring, cqe);
  1452. sleep(1);
  1453. if (!((*ring->sq.kflags) & IORING_SQ_CQ_OVERFLOW)) {
  1454. goto err;
  1455. }
  1456. /* multishot timer should be gone */
  1457. sqe = io_uring_get_sqe(ring);
  1458. if (!sqe) {
  1459. fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
  1460. goto err;
  1461. }
  1462. io_uring_prep_timeout_remove(sqe, 1, 0);
  1463. ret = io_uring_submit(ring);
  1464. if (ret <= 0) {
  1465. fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
  1466. goto err;
  1467. }
  1468. ret = io_uring_wait_cqe(ring, &cqe);
  1469. if (ret < 0) {
  1470. fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
  1471. goto err;
  1472. }
  1473. ret = cqe->res;
  1474. io_uring_cqe_seen(ring, cqe);
  1475. if (ret != -ETIME) {
  1476. fprintf(stderr, "%s: remove failed: %d %s\n", __FUNCTION__, ret, strerror(-ret));
  1477. goto err;
  1478. }
  1479. return 0;
  1480. err:
  1481. return 1;
  1482. }
  1483. static int test_eventfd(void)
  1484. {
  1485. struct __kernel_timespec ts = { .tv_sec = 5, };
  1486. struct io_uring_sqe *sqe;
  1487. struct io_uring ring;
  1488. int ev, ret;
  1489. ret = io_uring_queue_init(2, &ring, IORING_SETUP_DEFER_TASKRUN |
  1490. IORING_SETUP_SINGLE_ISSUER);
  1491. if (ret == -EINVAL) {
  1492. return T_EXIT_SKIP;
  1493. } else if (ret < 0) {
  1494. fprintf(stderr, "queue_init: %d\n", ret);
  1495. return T_EXIT_FAIL;
  1496. }
  1497. ev = eventfd(0, 0);
  1498. if (ev < 0) {
  1499. perror("eventfd");
  1500. return T_EXIT_SKIP;
  1501. }
  1502. ret = io_uring_register_eventfd(&ring, ev);
  1503. if (ret) {
  1504. fprintf(stderr, "register_eventfd: %d\n", ret);
  1505. return ret;
  1506. }
  1507. sqe = io_uring_get_sqe(&ring);
  1508. io_uring_prep_timeout(sqe, &ts, 100, 0);
  1509. sqe->user_data = 0x1234;
  1510. sqe->flags |= IOSQE_ASYNC;
  1511. io_uring_submit(&ring);
  1512. io_uring_queue_exit(&ring);
  1513. close(ev);
  1514. return T_EXIT_PASS;
  1515. }
  1516. int main(int argc, char *argv[])
  1517. {
  1518. struct io_uring ring, sqpoll_ring;
  1519. bool has_timeout_update, sqpoll;
  1520. struct io_uring_params p = { };
  1521. int ret;
  1522. if (argc > 1)
  1523. return 0;
  1524. ret = io_uring_queue_init_params(8, &ring, &p);
  1525. if (ret) {
  1526. fprintf(stderr, "ring setup failed\n");
  1527. return 1;
  1528. }
  1529. ret = io_uring_queue_init(8, &sqpoll_ring, IORING_SETUP_SQPOLL);
  1530. sqpoll = !ret;
  1531. ret = test_single_timeout(&ring);
  1532. if (ret) {
  1533. fprintf(stderr, "test_single_timeout failed\n");
  1534. return ret;
  1535. }
  1536. if (not_supported)
  1537. return 0;
  1538. ret = test_multi_timeout(&ring);
  1539. if (ret) {
  1540. fprintf(stderr, "test_multi_timeout failed\n");
  1541. return ret;
  1542. }
  1543. ret = test_single_timeout_abs(&ring);
  1544. if (ret) {
  1545. fprintf(stderr, "test_single_timeout_abs failed\n");
  1546. return ret;
  1547. }
  1548. ret = test_single_timeout_remove(&ring);
  1549. if (ret) {
  1550. fprintf(stderr, "test_single_timeout_remove failed\n");
  1551. return ret;
  1552. }
  1553. ret = test_single_timeout_remove_notfound(&ring);
  1554. if (ret) {
  1555. fprintf(stderr, "test_single_timeout_remove_notfound failed\n");
  1556. return ret;
  1557. }
  1558. ret = test_single_timeout_many(&ring);
  1559. if (ret) {
  1560. fprintf(stderr, "test_single_timeout_many failed\n");
  1561. return ret;
  1562. }
  1563. ret = test_single_timeout_nr(&ring, 1);
  1564. if (ret) {
  1565. fprintf(stderr, "test_single_timeout_nr(1) failed\n");
  1566. return ret;
  1567. }
  1568. ret = test_single_timeout_nr(&ring, 2);
  1569. if (ret) {
  1570. fprintf(stderr, "test_single_timeout_nr(2) failed\n");
  1571. return ret;
  1572. }
  1573. ret = test_multi_timeout_nr(&ring);
  1574. if (ret) {
  1575. fprintf(stderr, "test_multi_timeout_nr failed\n");
  1576. return ret;
  1577. }
  1578. ret = test_timeout_flags1(&ring);
  1579. if (ret) {
  1580. fprintf(stderr, "test_timeout_flags1 failed\n");
  1581. return ret;
  1582. }
  1583. ret = test_timeout_flags2(&ring);
  1584. if (ret) {
  1585. fprintf(stderr, "test_timeout_flags2 failed\n");
  1586. return ret;
  1587. }
  1588. ret = test_timeout_flags3(&ring);
  1589. if (ret) {
  1590. fprintf(stderr, "test_timeout_flags3 failed\n");
  1591. return ret;
  1592. }
  1593. ret = test_timeout_multishot(&ring);
  1594. if (ret && ret != T_EXIT_SKIP) {
  1595. fprintf(stderr, "test_timeout_multishot failed\n");
  1596. return ret;
  1597. }
  1598. ret = test_timeout_multishot_nr(&ring);
  1599. if (ret && ret != T_EXIT_SKIP) {
  1600. fprintf(stderr, "test_timeout_multishot_nr failed\n");
  1601. return ret;
  1602. }
  1603. /* io_uring_wait_cqe_timeout() may have left a timeout, reinit ring */
  1604. io_uring_queue_exit(&ring);
  1605. ret = io_uring_queue_init(8, &ring, 0);
  1606. if (ret) {
  1607. fprintf(stderr, "ring setup failed\n");
  1608. return 1;
  1609. }
  1610. ret = test_timeout_multishot_overflow(&ring);
  1611. if (ret && ret != T_EXIT_SKIP) {
  1612. fprintf(stderr, "test_timeout_multishot_overflow failed\n");
  1613. return ret;
  1614. }
  1615. /* io_uring_wait_cqe_timeout() may have left a timeout, reinit ring */
  1616. io_uring_queue_exit(&ring);
  1617. ret = io_uring_queue_init(8, &ring, 0);
  1618. if (ret) {
  1619. fprintf(stderr, "ring setup failed\n");
  1620. return 1;
  1621. }
  1622. ret = test_single_timeout_wait(&ring, &p);
  1623. if (ret) {
  1624. fprintf(stderr, "test_single_timeout_wait failed\n");
  1625. return ret;
  1626. }
  1627. /* io_uring_wait_cqes() may have left a timeout, reinit ring */
  1628. io_uring_queue_exit(&ring);
  1629. ret = io_uring_queue_init(8, &ring, 0);
  1630. if (ret) {
  1631. fprintf(stderr, "ring setup failed\n");
  1632. return 1;
  1633. }
  1634. ret = test_update_nonexistent_timeout(&ring);
  1635. has_timeout_update = (ret != -EINVAL);
  1636. if (has_timeout_update) {
  1637. if (ret) {
  1638. fprintf(stderr, "test_update_nonexistent_timeout failed\n");
  1639. return ret;
  1640. }
  1641. ret = test_update_invalid_flags(&ring);
  1642. if (ret) {
  1643. fprintf(stderr, "test_update_invalid_flags failed\n");
  1644. return ret;
  1645. }
  1646. ret = test_update_timeout(&ring, 0, false, false, false);
  1647. if (ret) {
  1648. fprintf(stderr, "test_update_timeout failed\n");
  1649. return ret;
  1650. }
  1651. ret = test_update_timeout(&ring, 1, false, false, false);
  1652. if (ret) {
  1653. fprintf(stderr, "test_update_timeout 1ms failed\n");
  1654. return ret;
  1655. }
  1656. ret = test_update_timeout(&ring, 1000, false, false, false);
  1657. if (ret) {
  1658. fprintf(stderr, "test_update_timeout 1s failed\n");
  1659. return ret;
  1660. }
  1661. ret = test_update_timeout(&ring, 0, true, true, false);
  1662. if (ret) {
  1663. fprintf(stderr, "test_update_timeout abs failed\n");
  1664. return ret;
  1665. }
  1666. ret = test_update_timeout(&ring, 0, false, true, false);
  1667. if (ret) {
  1668. fprintf(stderr, "test_update_timeout async failed\n");
  1669. return ret;
  1670. }
  1671. ret = test_update_timeout(&ring, 0, false, false, true);
  1672. if (ret) {
  1673. fprintf(stderr, "test_update_timeout linked failed\n");
  1674. return ret;
  1675. }
  1676. ret = test_update_multishot_timeouts(&ring, 200);
  1677. if (ret) {
  1678. fprintf(stderr, "test_update_multishot_timeouts linked failed\n");
  1679. return ret;
  1680. }
  1681. if (sqpoll) {
  1682. ret = test_update_timeout(&sqpoll_ring, 0, false, false,
  1683. false);
  1684. if (ret) {
  1685. fprintf(stderr, "test_update_timeout sqpoll"
  1686. "failed\n");
  1687. return ret;
  1688. }
  1689. }
  1690. }
  1691. ret = test_eventfd();
  1692. if (ret == T_EXIT_FAIL) {
  1693. fprintf(stderr, "test_eventfd failed\n");
  1694. return ret;
  1695. }
  1696. /*
  1697. * this test must go last, it kills the ring
  1698. */
  1699. ret = test_single_timeout_exit(&ring);
  1700. if (ret) {
  1701. fprintf(stderr, "test_single_timeout_exit failed\n");
  1702. return ret;
  1703. }
  1704. ret = test_timeout_link_cancel();
  1705. if (ret) {
  1706. fprintf(stderr, "test_timeout_link_cancel failed\n");
  1707. return ret;
  1708. }
  1709. ret = test_not_failing_links();
  1710. if (ret) {
  1711. fprintf(stderr, "test_not_failing_links failed\n");
  1712. return ret;
  1713. }
  1714. if (sqpoll)
  1715. io_uring_queue_exit(&sqpoll_ring);
  1716. return 0;
  1717. }