test_freezer.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #include <stdbool.h>
  3. #include <linux/limits.h>
  4. #include <sys/ptrace.h>
  5. #include <sys/types.h>
  6. #include <sys/mman.h>
  7. #include <unistd.h>
  8. #include <stdio.h>
  9. #include <errno.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <sys/wait.h>
  13. #include "../kselftest.h"
  14. #include "cgroup_util.h"
  15. #define DEBUG
  16. #ifdef DEBUG
  17. #define debug(args...) fprintf(stderr, args)
  18. #else
  19. #define debug(args...)
  20. #endif
  21. /*
  22. * Check if the cgroup is frozen by looking at the cgroup.events::frozen value.
  23. */
  24. static int cg_check_frozen(const char *cgroup, bool frozen)
  25. {
  26. if (frozen) {
  27. if (cg_read_strstr(cgroup, "cgroup.events", "frozen 1") != 0) {
  28. debug("Cgroup %s isn't frozen\n", cgroup);
  29. return -1;
  30. }
  31. } else {
  32. /*
  33. * Check the cgroup.events::frozen value.
  34. */
  35. if (cg_read_strstr(cgroup, "cgroup.events", "frozen 0") != 0) {
  36. debug("Cgroup %s is frozen\n", cgroup);
  37. return -1;
  38. }
  39. }
  40. return 0;
  41. }
  42. /*
  43. * Freeze the given cgroup.
  44. */
  45. static int cg_freeze_nowait(const char *cgroup, bool freeze)
  46. {
  47. return cg_write(cgroup, "cgroup.freeze", freeze ? "1" : "0");
  48. }
  49. /*
  50. * Attach a task to the given cgroup and wait for a cgroup frozen event.
  51. * All transient events (e.g. populated) are ignored.
  52. */
  53. static int cg_enter_and_wait_for_frozen(const char *cgroup, int pid,
  54. bool frozen)
  55. {
  56. int fd, ret = -1;
  57. int attempts;
  58. fd = cg_prepare_for_wait(cgroup);
  59. if (fd < 0)
  60. return fd;
  61. ret = cg_enter(cgroup, pid);
  62. if (ret)
  63. goto out;
  64. for (attempts = 0; attempts < 10; attempts++) {
  65. ret = cg_wait_for(fd);
  66. if (ret)
  67. break;
  68. ret = cg_check_frozen(cgroup, frozen);
  69. if (ret)
  70. continue;
  71. }
  72. out:
  73. close(fd);
  74. return ret;
  75. }
  76. /*
  77. * Freeze the given cgroup and wait for the inotify signal.
  78. * If there are no events in 10 seconds, treat this as an error.
  79. * Then check that the cgroup is in the desired state.
  80. */
  81. static int cg_freeze_wait(const char *cgroup, bool freeze)
  82. {
  83. int fd, ret = -1;
  84. fd = cg_prepare_for_wait(cgroup);
  85. if (fd < 0)
  86. return fd;
  87. ret = cg_freeze_nowait(cgroup, freeze);
  88. if (ret) {
  89. debug("Error: cg_freeze_nowait() failed\n");
  90. goto out;
  91. }
  92. ret = cg_wait_for(fd);
  93. if (ret)
  94. goto out;
  95. ret = cg_check_frozen(cgroup, freeze);
  96. out:
  97. close(fd);
  98. return ret;
  99. }
  100. /*
  101. * A simple process running in a sleep loop until being
  102. * re-parented.
  103. */
  104. static int child_fn(const char *cgroup, void *arg)
  105. {
  106. int ppid = getppid();
  107. while (getppid() == ppid)
  108. usleep(1000);
  109. return getppid() == ppid;
  110. }
  111. /*
  112. * A simple test for the cgroup freezer: populated the cgroup with 100
  113. * running processes and freeze it. Then unfreeze it. Then it kills all
  114. * processes and destroys the cgroup.
  115. */
  116. static int test_cgfreezer_simple(const char *root)
  117. {
  118. int ret = KSFT_FAIL;
  119. char *cgroup = NULL;
  120. int i;
  121. cgroup = cg_name(root, "cg_test_simple");
  122. if (!cgroup)
  123. goto cleanup;
  124. if (cg_create(cgroup))
  125. goto cleanup;
  126. for (i = 0; i < 100; i++)
  127. cg_run_nowait(cgroup, child_fn, NULL);
  128. if (cg_wait_for_proc_count(cgroup, 100))
  129. goto cleanup;
  130. if (cg_check_frozen(cgroup, false))
  131. goto cleanup;
  132. if (cg_freeze_wait(cgroup, true))
  133. goto cleanup;
  134. if (cg_freeze_wait(cgroup, false))
  135. goto cleanup;
  136. ret = KSFT_PASS;
  137. cleanup:
  138. if (cgroup)
  139. cg_destroy(cgroup);
  140. free(cgroup);
  141. return ret;
  142. }
  143. /*
  144. * The test creates the following hierarchy:
  145. * A
  146. * / / \ \
  147. * B E I K
  148. * /\ |
  149. * C D F
  150. * |
  151. * G
  152. * |
  153. * H
  154. *
  155. * with a process in C, H and 3 processes in K.
  156. * Then it tries to freeze and unfreeze the whole tree.
  157. */
  158. static int test_cgfreezer_tree(const char *root)
  159. {
  160. char *cgroup[10] = {0};
  161. int ret = KSFT_FAIL;
  162. int i;
  163. cgroup[0] = cg_name(root, "cg_test_tree_A");
  164. if (!cgroup[0])
  165. goto cleanup;
  166. cgroup[1] = cg_name(cgroup[0], "B");
  167. if (!cgroup[1])
  168. goto cleanup;
  169. cgroup[2] = cg_name(cgroup[1], "C");
  170. if (!cgroup[2])
  171. goto cleanup;
  172. cgroup[3] = cg_name(cgroup[1], "D");
  173. if (!cgroup[3])
  174. goto cleanup;
  175. cgroup[4] = cg_name(cgroup[0], "E");
  176. if (!cgroup[4])
  177. goto cleanup;
  178. cgroup[5] = cg_name(cgroup[4], "F");
  179. if (!cgroup[5])
  180. goto cleanup;
  181. cgroup[6] = cg_name(cgroup[5], "G");
  182. if (!cgroup[6])
  183. goto cleanup;
  184. cgroup[7] = cg_name(cgroup[6], "H");
  185. if (!cgroup[7])
  186. goto cleanup;
  187. cgroup[8] = cg_name(cgroup[0], "I");
  188. if (!cgroup[8])
  189. goto cleanup;
  190. cgroup[9] = cg_name(cgroup[0], "K");
  191. if (!cgroup[9])
  192. goto cleanup;
  193. for (i = 0; i < 10; i++)
  194. if (cg_create(cgroup[i]))
  195. goto cleanup;
  196. cg_run_nowait(cgroup[2], child_fn, NULL);
  197. cg_run_nowait(cgroup[7], child_fn, NULL);
  198. cg_run_nowait(cgroup[9], child_fn, NULL);
  199. cg_run_nowait(cgroup[9], child_fn, NULL);
  200. cg_run_nowait(cgroup[9], child_fn, NULL);
  201. /*
  202. * Wait until all child processes will enter
  203. * corresponding cgroups.
  204. */
  205. if (cg_wait_for_proc_count(cgroup[2], 1) ||
  206. cg_wait_for_proc_count(cgroup[7], 1) ||
  207. cg_wait_for_proc_count(cgroup[9], 3))
  208. goto cleanup;
  209. /*
  210. * Freeze B.
  211. */
  212. if (cg_freeze_wait(cgroup[1], true))
  213. goto cleanup;
  214. /*
  215. * Freeze F.
  216. */
  217. if (cg_freeze_wait(cgroup[5], true))
  218. goto cleanup;
  219. /*
  220. * Freeze G.
  221. */
  222. if (cg_freeze_wait(cgroup[6], true))
  223. goto cleanup;
  224. /*
  225. * Check that A and E are not frozen.
  226. */
  227. if (cg_check_frozen(cgroup[0], false))
  228. goto cleanup;
  229. if (cg_check_frozen(cgroup[4], false))
  230. goto cleanup;
  231. /*
  232. * Freeze A. Check that A, B and E are frozen.
  233. */
  234. if (cg_freeze_wait(cgroup[0], true))
  235. goto cleanup;
  236. if (cg_check_frozen(cgroup[1], true))
  237. goto cleanup;
  238. if (cg_check_frozen(cgroup[4], true))
  239. goto cleanup;
  240. /*
  241. * Unfreeze B, F and G
  242. */
  243. if (cg_freeze_nowait(cgroup[1], false))
  244. goto cleanup;
  245. if (cg_freeze_nowait(cgroup[5], false))
  246. goto cleanup;
  247. if (cg_freeze_nowait(cgroup[6], false))
  248. goto cleanup;
  249. /*
  250. * Check that C and H are still frozen.
  251. */
  252. if (cg_check_frozen(cgroup[2], true))
  253. goto cleanup;
  254. if (cg_check_frozen(cgroup[7], true))
  255. goto cleanup;
  256. /*
  257. * Unfreeze A. Check that A, C and K are not frozen.
  258. */
  259. if (cg_freeze_wait(cgroup[0], false))
  260. goto cleanup;
  261. if (cg_check_frozen(cgroup[2], false))
  262. goto cleanup;
  263. if (cg_check_frozen(cgroup[9], false))
  264. goto cleanup;
  265. ret = KSFT_PASS;
  266. cleanup:
  267. for (i = 9; i >= 0 && cgroup[i]; i--) {
  268. cg_destroy(cgroup[i]);
  269. free(cgroup[i]);
  270. }
  271. return ret;
  272. }
  273. /*
  274. * A fork bomb emulator.
  275. */
  276. static int forkbomb_fn(const char *cgroup, void *arg)
  277. {
  278. int ppid;
  279. fork();
  280. fork();
  281. ppid = getppid();
  282. while (getppid() == ppid)
  283. usleep(1000);
  284. return getppid() == ppid;
  285. }
  286. /*
  287. * The test runs a fork bomb in a cgroup and tries to freeze it.
  288. * Then it kills all processes and checks that cgroup isn't populated
  289. * anymore.
  290. */
  291. static int test_cgfreezer_forkbomb(const char *root)
  292. {
  293. int ret = KSFT_FAIL;
  294. char *cgroup = NULL;
  295. cgroup = cg_name(root, "cg_forkbomb_test");
  296. if (!cgroup)
  297. goto cleanup;
  298. if (cg_create(cgroup))
  299. goto cleanup;
  300. cg_run_nowait(cgroup, forkbomb_fn, NULL);
  301. usleep(100000);
  302. if (cg_freeze_wait(cgroup, true))
  303. goto cleanup;
  304. if (cg_killall(cgroup))
  305. goto cleanup;
  306. if (cg_wait_for_proc_count(cgroup, 0))
  307. goto cleanup;
  308. ret = KSFT_PASS;
  309. cleanup:
  310. if (cgroup)
  311. cg_destroy(cgroup);
  312. free(cgroup);
  313. return ret;
  314. }
  315. /*
  316. * The test creates a cgroups and freezes it. Then it creates a child cgroup
  317. * and populates it with a task. After that it checks that the child cgroup
  318. * is frozen and the parent cgroup remains frozen too.
  319. */
  320. static int test_cgfreezer_mkdir(const char *root)
  321. {
  322. int ret = KSFT_FAIL;
  323. char *parent, *child = NULL;
  324. int pid;
  325. parent = cg_name(root, "cg_test_mkdir_A");
  326. if (!parent)
  327. goto cleanup;
  328. child = cg_name(parent, "cg_test_mkdir_B");
  329. if (!child)
  330. goto cleanup;
  331. if (cg_create(parent))
  332. goto cleanup;
  333. if (cg_freeze_wait(parent, true))
  334. goto cleanup;
  335. if (cg_create(child))
  336. goto cleanup;
  337. pid = cg_run_nowait(child, child_fn, NULL);
  338. if (pid < 0)
  339. goto cleanup;
  340. if (cg_wait_for_proc_count(child, 1))
  341. goto cleanup;
  342. if (cg_check_frozen(child, true))
  343. goto cleanup;
  344. if (cg_check_frozen(parent, true))
  345. goto cleanup;
  346. ret = KSFT_PASS;
  347. cleanup:
  348. if (child)
  349. cg_destroy(child);
  350. free(child);
  351. if (parent)
  352. cg_destroy(parent);
  353. free(parent);
  354. return ret;
  355. }
  356. /*
  357. * The test creates two nested cgroups, freezes the parent
  358. * and removes the child. Then it checks that the parent cgroup
  359. * remains frozen and it's possible to create a new child
  360. * without unfreezing. The new child is frozen too.
  361. */
  362. static int test_cgfreezer_rmdir(const char *root)
  363. {
  364. int ret = KSFT_FAIL;
  365. char *parent, *child = NULL;
  366. parent = cg_name(root, "cg_test_rmdir_A");
  367. if (!parent)
  368. goto cleanup;
  369. child = cg_name(parent, "cg_test_rmdir_B");
  370. if (!child)
  371. goto cleanup;
  372. if (cg_create(parent))
  373. goto cleanup;
  374. if (cg_create(child))
  375. goto cleanup;
  376. if (cg_freeze_wait(parent, true))
  377. goto cleanup;
  378. if (cg_destroy(child))
  379. goto cleanup;
  380. if (cg_check_frozen(parent, true))
  381. goto cleanup;
  382. if (cg_create(child))
  383. goto cleanup;
  384. if (cg_check_frozen(child, true))
  385. goto cleanup;
  386. ret = KSFT_PASS;
  387. cleanup:
  388. if (child)
  389. cg_destroy(child);
  390. free(child);
  391. if (parent)
  392. cg_destroy(parent);
  393. free(parent);
  394. return ret;
  395. }
  396. /*
  397. * The test creates two cgroups: A and B, runs a process in A
  398. * and performs several migrations:
  399. * 1) A (running) -> B (frozen)
  400. * 2) B (frozen) -> A (running)
  401. * 3) A (frozen) -> B (frozen)
  402. *
  403. * On each step it checks the actual state of both cgroups.
  404. */
  405. static int test_cgfreezer_migrate(const char *root)
  406. {
  407. int ret = KSFT_FAIL;
  408. char *cgroup[2] = {0};
  409. int pid;
  410. cgroup[0] = cg_name(root, "cg_test_migrate_A");
  411. if (!cgroup[0])
  412. goto cleanup;
  413. cgroup[1] = cg_name(root, "cg_test_migrate_B");
  414. if (!cgroup[1])
  415. goto cleanup;
  416. if (cg_create(cgroup[0]))
  417. goto cleanup;
  418. if (cg_create(cgroup[1]))
  419. goto cleanup;
  420. pid = cg_run_nowait(cgroup[0], child_fn, NULL);
  421. if (pid < 0)
  422. goto cleanup;
  423. if (cg_wait_for_proc_count(cgroup[0], 1))
  424. goto cleanup;
  425. /*
  426. * Migrate from A (running) to B (frozen)
  427. */
  428. if (cg_freeze_wait(cgroup[1], true))
  429. goto cleanup;
  430. if (cg_enter_and_wait_for_frozen(cgroup[1], pid, true))
  431. goto cleanup;
  432. if (cg_check_frozen(cgroup[0], false))
  433. goto cleanup;
  434. /*
  435. * Migrate from B (frozen) to A (running)
  436. */
  437. if (cg_enter_and_wait_for_frozen(cgroup[0], pid, false))
  438. goto cleanup;
  439. if (cg_check_frozen(cgroup[1], true))
  440. goto cleanup;
  441. /*
  442. * Migrate from A (frozen) to B (frozen)
  443. */
  444. if (cg_freeze_wait(cgroup[0], true))
  445. goto cleanup;
  446. if (cg_enter_and_wait_for_frozen(cgroup[1], pid, true))
  447. goto cleanup;
  448. if (cg_check_frozen(cgroup[0], true))
  449. goto cleanup;
  450. ret = KSFT_PASS;
  451. cleanup:
  452. if (cgroup[0])
  453. cg_destroy(cgroup[0]);
  454. free(cgroup[0]);
  455. if (cgroup[1])
  456. cg_destroy(cgroup[1]);
  457. free(cgroup[1]);
  458. return ret;
  459. }
  460. /*
  461. * The test checks that ptrace works with a tracing process in a frozen cgroup.
  462. */
  463. static int test_cgfreezer_ptrace(const char *root)
  464. {
  465. int ret = KSFT_FAIL;
  466. char *cgroup = NULL;
  467. siginfo_t siginfo;
  468. int pid;
  469. cgroup = cg_name(root, "cg_test_ptrace");
  470. if (!cgroup)
  471. goto cleanup;
  472. if (cg_create(cgroup))
  473. goto cleanup;
  474. pid = cg_run_nowait(cgroup, child_fn, NULL);
  475. if (pid < 0)
  476. goto cleanup;
  477. if (cg_wait_for_proc_count(cgroup, 1))
  478. goto cleanup;
  479. if (cg_freeze_wait(cgroup, true))
  480. goto cleanup;
  481. if (ptrace(PTRACE_SEIZE, pid, NULL, NULL))
  482. goto cleanup;
  483. if (ptrace(PTRACE_INTERRUPT, pid, NULL, NULL))
  484. goto cleanup;
  485. waitpid(pid, NULL, 0);
  486. /*
  487. * Cgroup has to remain frozen, however the test task
  488. * is in traced state.
  489. */
  490. if (cg_check_frozen(cgroup, true))
  491. goto cleanup;
  492. if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo))
  493. goto cleanup;
  494. if (ptrace(PTRACE_DETACH, pid, NULL, NULL))
  495. goto cleanup;
  496. if (cg_check_frozen(cgroup, true))
  497. goto cleanup;
  498. ret = KSFT_PASS;
  499. cleanup:
  500. if (cgroup)
  501. cg_destroy(cgroup);
  502. free(cgroup);
  503. return ret;
  504. }
  505. /*
  506. * Check if the process is stopped.
  507. */
  508. static int proc_check_stopped(int pid)
  509. {
  510. char buf[PAGE_SIZE];
  511. int len;
  512. len = proc_read_text(pid, 0, "stat", buf, sizeof(buf));
  513. if (len == -1) {
  514. debug("Can't get %d stat\n", pid);
  515. return -1;
  516. }
  517. if (strstr(buf, "(test_freezer) T ") == NULL) {
  518. debug("Process %d in the unexpected state: %s\n", pid, buf);
  519. return -1;
  520. }
  521. return 0;
  522. }
  523. /*
  524. * Test that it's possible to freeze a cgroup with a stopped process.
  525. */
  526. static int test_cgfreezer_stopped(const char *root)
  527. {
  528. int pid, ret = KSFT_FAIL;
  529. char *cgroup = NULL;
  530. cgroup = cg_name(root, "cg_test_stopped");
  531. if (!cgroup)
  532. goto cleanup;
  533. if (cg_create(cgroup))
  534. goto cleanup;
  535. pid = cg_run_nowait(cgroup, child_fn, NULL);
  536. if (cg_wait_for_proc_count(cgroup, 1))
  537. goto cleanup;
  538. if (kill(pid, SIGSTOP))
  539. goto cleanup;
  540. if (cg_check_frozen(cgroup, false))
  541. goto cleanup;
  542. if (cg_freeze_wait(cgroup, true))
  543. goto cleanup;
  544. if (cg_freeze_wait(cgroup, false))
  545. goto cleanup;
  546. if (proc_check_stopped(pid))
  547. goto cleanup;
  548. ret = KSFT_PASS;
  549. cleanup:
  550. if (cgroup)
  551. cg_destroy(cgroup);
  552. free(cgroup);
  553. return ret;
  554. }
  555. /*
  556. * Test that it's possible to freeze a cgroup with a ptraced process.
  557. */
  558. static int test_cgfreezer_ptraced(const char *root)
  559. {
  560. int pid, ret = KSFT_FAIL;
  561. char *cgroup = NULL;
  562. siginfo_t siginfo;
  563. cgroup = cg_name(root, "cg_test_ptraced");
  564. if (!cgroup)
  565. goto cleanup;
  566. if (cg_create(cgroup))
  567. goto cleanup;
  568. pid = cg_run_nowait(cgroup, child_fn, NULL);
  569. if (cg_wait_for_proc_count(cgroup, 1))
  570. goto cleanup;
  571. if (ptrace(PTRACE_SEIZE, pid, NULL, NULL))
  572. goto cleanup;
  573. if (ptrace(PTRACE_INTERRUPT, pid, NULL, NULL))
  574. goto cleanup;
  575. waitpid(pid, NULL, 0);
  576. if (cg_check_frozen(cgroup, false))
  577. goto cleanup;
  578. if (cg_freeze_wait(cgroup, true))
  579. goto cleanup;
  580. /*
  581. * cg_check_frozen(cgroup, true) will fail here,
  582. * because the task in in the TRACEd state.
  583. */
  584. if (cg_freeze_wait(cgroup, false))
  585. goto cleanup;
  586. if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo))
  587. goto cleanup;
  588. if (ptrace(PTRACE_DETACH, pid, NULL, NULL))
  589. goto cleanup;
  590. ret = KSFT_PASS;
  591. cleanup:
  592. if (cgroup)
  593. cg_destroy(cgroup);
  594. free(cgroup);
  595. return ret;
  596. }
  597. static int vfork_fn(const char *cgroup, void *arg)
  598. {
  599. int pid = vfork();
  600. if (pid == 0)
  601. while (true)
  602. sleep(1);
  603. return pid;
  604. }
  605. /*
  606. * Test that it's possible to freeze a cgroup with a process,
  607. * which called vfork() and is waiting for a child.
  608. */
  609. static int test_cgfreezer_vfork(const char *root)
  610. {
  611. int ret = KSFT_FAIL;
  612. char *cgroup = NULL;
  613. cgroup = cg_name(root, "cg_test_vfork");
  614. if (!cgroup)
  615. goto cleanup;
  616. if (cg_create(cgroup))
  617. goto cleanup;
  618. cg_run_nowait(cgroup, vfork_fn, NULL);
  619. if (cg_wait_for_proc_count(cgroup, 2))
  620. goto cleanup;
  621. if (cg_freeze_wait(cgroup, true))
  622. goto cleanup;
  623. ret = KSFT_PASS;
  624. cleanup:
  625. if (cgroup)
  626. cg_destroy(cgroup);
  627. free(cgroup);
  628. return ret;
  629. }
  630. #define T(x) { x, #x }
  631. struct cgfreezer_test {
  632. int (*fn)(const char *root);
  633. const char *name;
  634. } tests[] = {
  635. T(test_cgfreezer_simple),
  636. T(test_cgfreezer_tree),
  637. T(test_cgfreezer_forkbomb),
  638. T(test_cgfreezer_mkdir),
  639. T(test_cgfreezer_rmdir),
  640. T(test_cgfreezer_migrate),
  641. T(test_cgfreezer_ptrace),
  642. T(test_cgfreezer_stopped),
  643. T(test_cgfreezer_ptraced),
  644. T(test_cgfreezer_vfork),
  645. };
  646. #undef T
  647. int main(int argc, char *argv[])
  648. {
  649. char root[PATH_MAX];
  650. int i, ret = EXIT_SUCCESS;
  651. if (cg_find_unified_root(root, sizeof(root)))
  652. ksft_exit_skip("cgroup v2 isn't mounted\n");
  653. for (i = 0; i < ARRAY_SIZE(tests); i++) {
  654. switch (tests[i].fn(root)) {
  655. case KSFT_PASS:
  656. ksft_test_result_pass("%s\n", tests[i].name);
  657. break;
  658. case KSFT_SKIP:
  659. ksft_test_result_skip("%s\n", tests[i].name);
  660. break;
  661. default:
  662. ret = EXIT_FAILURE;
  663. ksft_test_result_fail("%s\n", tests[i].name);
  664. break;
  665. }
  666. }
  667. return ret;
  668. }