1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> 4f08c3bdfSopenharmony_ci */ 5f08c3bdfSopenharmony_ci 6f08c3bdfSopenharmony_ci/* 7f08c3bdfSopenharmony_ci * Tests tst_run_as_child() 8f08c3bdfSopenharmony_ci */ 9f08c3bdfSopenharmony_ci 10f08c3bdfSopenharmony_ci#include "tst_test.h" 11f08c3bdfSopenharmony_ci 12f08c3bdfSopenharmony_cistatic void child_fn(unsigned int i) 13f08c3bdfSopenharmony_ci{ 14f08c3bdfSopenharmony_ci switch (i) { 15f08c3bdfSopenharmony_ci case 0: 16f08c3bdfSopenharmony_ci tst_res(TPASS, "PASSED message"); 17f08c3bdfSopenharmony_ci break; 18f08c3bdfSopenharmony_ci case 1: 19f08c3bdfSopenharmony_ci tst_brk(TBROK, "BROKEN message"); 20f08c3bdfSopenharmony_ci break; 21f08c3bdfSopenharmony_ci } 22f08c3bdfSopenharmony_ci} 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_cistatic void setup(void) 25f08c3bdfSopenharmony_ci{ 26f08c3bdfSopenharmony_ci tst_res(TINFO, "setup() executed by pid %i", getpid()); 27f08c3bdfSopenharmony_ci} 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_cistatic void cleanup(void) 30f08c3bdfSopenharmony_ci{ 31f08c3bdfSopenharmony_ci tst_res(TINFO, "cleanup() executed by pid %i", getpid()); 32f08c3bdfSopenharmony_ci} 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_cistatic void do_test(unsigned int i) 35f08c3bdfSopenharmony_ci{ 36f08c3bdfSopenharmony_ci if (SAFE_FORK() == 0) 37f08c3bdfSopenharmony_ci child_fn(i); 38f08c3bdfSopenharmony_ci} 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_cistatic struct tst_test test = { 41f08c3bdfSopenharmony_ci .tcnt = 2, 42f08c3bdfSopenharmony_ci .test = do_test, 43f08c3bdfSopenharmony_ci .setup = setup, 44f08c3bdfSopenharmony_ci .cleanup = cleanup, 45f08c3bdfSopenharmony_ci .forks_child = 1, 46f08c3bdfSopenharmony_ci}; 47