Deleted Added
full compact
doat.c (179084) doat.c (219568)
1/*-
2 * Copyright (c) 2007 Roman Divacky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2007 Roman Divacky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/tools/regression/doat/doat.c 179084 2008-05-18 08:34:04Z rdivacky $
26 * $FreeBSD: head/tools/regression/doat/doat.c 219568 2011-03-12 14:47:54Z brucec $
27 */
28
27 */
28
29#include <sys/types.h>
30#include <sys/syscall.h>
31#include <sys/stat.h>
32
29#include <errno.h>
30#include <fcntl.h>
31#include <stdbool.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
33#include <errno.h>
34#include <fcntl.h>
35#include <stdbool.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
35#include <sys/types.h>
36#include <sys/syscall.h>
37#include <sys/stat.h>
39#include <unistd.h>
38
40
41void cleanup(void);
42void setup(void);
43void setup_once(void);
44
39union param {
40 int i;
45union param {
46 int i;
41 char *cp;
47 const char *cp;
42 mode_t m;
43 dev_t d;
44 void *vp;
45 uid_t u;
46 gid_t g;
48 mode_t m;
49 dev_t d;
50 void *vp;
51 uid_t u;
52 gid_t g;
47 char **cpp;
53 const char **cpp;
48};
49
50struct testcase {
51 int result;
52 union param params[5]; /* no *at syscall with more than 5 params */
53};
54
55struct test {
56 int syscall;
57 int num_of_cases;
54};
55
56struct testcase {
57 int result;
58 union param params[5]; /* no *at syscall with more than 5 params */
59};
60
61struct test {
62 int syscall;
63 int num_of_cases;
58 char *name;
64 const char *name;
59 struct testcase tests[10]; /* no more than 10 tests */
60
61};
62
63struct test *tests;
64#define NUM_OF_TESTS 14 /* we dont want the fexecve test to run */
65
66char *absolute_path = NULL;
65 struct testcase tests[10]; /* no more than 10 tests */
66
67};
68
69struct test *tests;
70#define NUM_OF_TESTS 14 /* we dont want the fexecve test to run */
71
72char *absolute_path = NULL;
67char *relative_path = "tmp/";
68char *not_dir_path = "/bin/date";
73const char *relative_path = "tmp/";
74const char *not_dir_path = "/bin/date";
69
75
70char *file = "foo";
76const char *file = "foo";
71char *absolute_file = NULL;
72char *relative_file = NULL;
77char *absolute_file = NULL;
78char *relative_file = NULL;
73char *symlinkf = "link";
74char *newlink = "nlink1";
75char *newlink2 = "nlink2";
76char *newlink3 = "nlink3";
77char *newdir = "newdir";
78char *fifo = "fifo";
79char *nod = "nod";
80char *newfile = "newfile";
81char *newslink = "nslink1";
79const char *symlinkf = "link";
80const char *newlink = "nlink1";
81const char *newlink2 = "nlink2";
82const char *newlink3 = "nlink3";
83const char *newdir = "newdir";
84const char *fifo = "fifo";
85const char *nod = "nod";
86const char *newfile = "newfile";
87const char *newslink = "nslink1";
82
83bool dir_exist = false;
84bool file_exist = false;
85bool link_exist = false;
86
87int rel_fd, abs_fd, notd_fd, exec_fd;
88
89struct timeval times[2];
90struct stat buf;
88
89bool dir_exist = false;
90bool file_exist = false;
91bool link_exist = false;
92
93int rel_fd, abs_fd, notd_fd, exec_fd;
94
95struct timeval times[2];
96struct stat buf;
91char *pargv[2] = { "/bin/date", NULL };
97const char *pargv[2] = { "/bin/date", NULL };
92#define PATH_MAX 1024
93char cbuf[PATH_MAX];
94
95void
98#define PATH_MAX 1024
99char cbuf[PATH_MAX];
100
101void
96setup()
102setup(void)
97{
98 int i, error;
103{
104 int i, error;
99 size_t siz;
100 struct stat sb;
101
102 tests = calloc(NUM_OF_TESTS, sizeof(struct test));
103 if (tests == NULL) {
104 perror("");
105 exit(0);
106 }
107

--- 494 unchanged lines hidden (view full) ---

602 /* This is EXPECTED to execve /bin/date, so dont expect OK output */
603 tests[14].tests[1].result = 0;
604 tests[14].tests[1].params[0].i = exec_fd;
605 tests[14].tests[1].params[1].cpp = pargv;
606 tests[14].tests[1].params[2].cpp = NULL;
607}
608
609void
105 struct stat sb;
106
107 tests = calloc(NUM_OF_TESTS, sizeof(struct test));
108 if (tests == NULL) {
109 perror("");
110 exit(0);
111 }
112

--- 494 unchanged lines hidden (view full) ---

607 /* This is EXPECTED to execve /bin/date, so dont expect OK output */
608 tests[14].tests[1].result = 0;
609 tests[14].tests[1].params[0].i = exec_fd;
610 tests[14].tests[1].params[1].cpp = pargv;
611 tests[14].tests[1].params[2].cpp = NULL;
612}
613
614void
610cleanup()
615cleanup(void)
611{
612 system("/bin/sh -c 'rm -rf tmp'");
613}
614
615void
616{
617 system("/bin/sh -c 'rm -rf tmp'");
618}
619
620void
616setup_once()
621setup_once(void)
617{
618}
619
620int
621main(int argc, char *argv[])
622{
623 int i,j;
624 int error;
625
622{
623}
624
625int
626main(int argc, char *argv[])
627{
628 int i,j;
629 int error;
630
631 (void)argc;
632 (void)argv;
633
626 setup();
627
628 for (i = 0; i < NUM_OF_TESTS; i++) {
634 setup();
635
636 for (i = 0; i < NUM_OF_TESTS; i++) {
629 printf("\nTest: %s\n", tests[i].name);
637 printf("\nTest: %s\n", tests[i].name);
630 for (j = 0; j < tests[i].num_of_cases; j++) {
631 error = syscall(tests[i].syscall,
632 tests[i].tests[j].params[0],
633 tests[i].tests[j].params[1],
634 tests[i].tests[j].params[2],
635 tests[i].tests[j].params[3],
636 tests[i].tests[j].params[4]);
637 if (error == 0) {

--- 9 unchanged lines hidden (view full) ---

647 else {
648 if (error != tests[i].tests[j].result) {
649 printf("#%i ... BAD: ", j);
650 printf("expected %i, but got %i\n", tests[i].tests[j].result, error);
651 } else
652 printf("#%i ... OK\n", j);
653 }
654 }
638 for (j = 0; j < tests[i].num_of_cases; j++) {
639 error = syscall(tests[i].syscall,
640 tests[i].tests[j].params[0],
641 tests[i].tests[j].params[1],
642 tests[i].tests[j].params[2],
643 tests[i].tests[j].params[3],
644 tests[i].tests[j].params[4]);
645 if (error == 0) {

--- 9 unchanged lines hidden (view full) ---

655 else {
656 if (error != tests[i].tests[j].result) {
657 printf("#%i ... BAD: ", j);
658 printf("expected %i, but got %i\n", tests[i].tests[j].result, error);
659 } else
660 printf("#%i ... OK\n", j);
661 }
662 }
655
656
657 }
658 }
659
660 cleanup();
661
663 }
664 }
665
666 cleanup();
667
662
663 return (0);
664}
668 return (0);
669}