Home | History | Annotate | Download | only in newlib_tests
      1 /*
      2  * Copyright (c) 2016 Cyril Hrubis <chrubis (at) suse.cz>
      3  *
      4  * This program is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU General Public License as
      6  * published by the Free Software Foundation; either version 2 of
      7  * the License, or (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it would be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program; if not, write the Free Software Foundation,
     16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     17  */
     18 
     19 /*
     20  * Tests tst_run_as_child()
     21  */
     22 
     23 #include "tst_test.h"
     24 
     25 static void child_fn(unsigned int i)
     26 {
     27 	switch (i) {
     28 	case 0:
     29 		tst_res(TPASS, "PASSED message");
     30 	break;
     31 	case 1:
     32 		tst_brk(TBROK, "BROKEN message");
     33 	break;
     34 	}
     35 }
     36 
     37 static void setup(void)
     38 {
     39 	tst_res(TINFO, "setup() executed by pid %i", getpid());
     40 }
     41 
     42 static void cleanup(void)
     43 {
     44 	tst_res(TINFO, "cleanup() executed by pid %i", getpid());
     45 }
     46 
     47 static void do_test(unsigned int i)
     48 {
     49 	if (SAFE_FORK() == 0)
     50 		child_fn(i);
     51 }
     52 
     53 static struct tst_test test = {
     54 	.tid = "test04",
     55 	.tcnt = 2,
     56 	.test = do_test,
     57 	.setup = setup,
     58 	.cleanup = cleanup,
     59 	.forks_child = 1,
     60 };
     61