~ubuntu-branches/debian/sid/cde/sid

« back to all changes in this revision

Viewing changes to tests/at_syscalls_test/at_syscalls_test.c

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2012-02-03 19:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20120203192705-ll6f1nr45ead65ed
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// test using absolute paths, so cde-exec should redirect all of these
 
2
// calls within the package
 
3
 
 
4
#include <sys/stat.h>
 
5
#include <fcntl.h>
 
6
#include <assert.h>
 
7
#include <utime.h>
 
8
 
 
9
#define PWD "/home/pgbovine/CDE/tests/at_syscalls_test/"
 
10
 
 
11
 
 
12
// extracted from fcntl.h
 
13
 
 
14
# define AT_FDCWD               -100    /* Special value used to indicate
 
15
                                           the *at functions should use the
 
16
                                           current working directory. */
 
17
# define AT_SYMLINK_NOFOLLOW    0x100   /* Do not follow symbolic links.  */
 
18
# define AT_REMOVEDIR           0x200   /* Remove directory instead of
 
19
                                           unlinking file.  */
 
20
# define AT_SYMLINK_FOLLOW      0x400   /* Follow symbolic links.  */
 
21
# define AT_EACCESS             0x200   /* Test access permitted for
 
22
                                           effective IDs, not real IDs.  */
 
23
 
 
24
 
 
25
// testing strategy:
 
26
//
 
27
// first:
 
28
// - use absolute paths to make *at syscalls
 
29
// - use relative paths to do assertion checks
 
30
//
 
31
//
 
32
// then flip it around and use relative paths to make syscalls and
 
33
// absolute paths to do assertion checks (TODO: implement this!)
 
34
 
 
35
int main() {
 
36
  struct stat st;
 
37
  struct stat st2;
 
38
 
 
39
  openat(AT_FDCWD, PWD "openat.txt", O_CREAT | O_WRONLY, 0644);
 
40
  assert(stat("openat.txt", &st) == 0); // relative path
 
41
 
 
42
  assert(faccessat(AT_FDCWD, PWD "openat.txt", F_OK, 0) == 0);
 
43
  assert(fstatat(AT_FDCWD, PWD "openat.txt", &st2, 0) == 0);
 
44
  assert(fchmodat(AT_FDCWD, PWD "openat.txt", 0777, 0) == 0);
 
45
 
 
46
  struct timeval my_times[2];
 
47
  my_times[0].tv_sec = 0;
 
48
  my_times[0].tv_usec = 0;
 
49
  my_times[1].tv_sec = 0;
 
50
  my_times[1].tv_usec = 0;
 
51
  assert(futimesat(AT_FDCWD, PWD "openat.txt", my_times, 0) == 0);
 
52
 
 
53
  // see /etc/passwd, user 'pgbovine' is 508:100
 
54
  assert(fchownat(AT_FDCWD, PWD "openat.txt", 508, 100, 0) == 0);
 
55
 
 
56
  assert(linkat(AT_FDCWD, PWD "openat.txt", AT_FDCWD, PWD "openat_hardlink.txt", 0) == 0);
 
57
  assert(stat("openat_hardlink.txt", &st) == 0); // relative path
 
58
 
 
59
  assert(symlinkat(PWD "openat.txt", AT_FDCWD, PWD "openat_symlink.txt") == 0);
 
60
  assert(lstat("openat_symlink.txt", &st) == 0); // relative path
 
61
 
 
62
  char res[300];
 
63
  assert(readlinkat(AT_FDCWD, PWD "openat_symlink.txt", res, sizeof(res)) > 0);
 
64
 
 
65
  assert(renameat(AT_FDCWD, PWD "openat.txt", AT_FDCWD, PWD "openat_newname.txt", 0) == 0);
 
66
  assert(stat("openat.txt", &st) != 0); // should not exist anymore
 
67
  assert(stat("openat_newname.txt", &st) == 0); // relative path
 
68
 
 
69
  unlinkat(AT_FDCWD, PWD "openat_newname.txt", 0);
 
70
  unlinkat(AT_FDCWD, PWD "openat_hardlink.txt", 0);
 
71
  unlinkat(AT_FDCWD, PWD "openat_symlink.txt", 0);
 
72
 
 
73
 
 
74
  mknodat(AT_FDCWD, PWD "mknodat.fifo", S_IFIFO);
 
75
  assert(stat("mknodat.fifo", &st) == 0); // relative path
 
76
  unlinkat(AT_FDCWD, PWD "mknodat.fifo", 0);
 
77
 
 
78
  mkdirat(AT_FDCWD, PWD "mkdirat_dir", 0);
 
79
  assert(stat("mkdirat_dir", &st) == 0); // relative path
 
80
  unlinkat(AT_FDCWD, PWD "mkdirat_dir", AT_REMOVEDIR); // like 'rmdir'
 
81
 
 
82
  return 0;
 
83
}
 
84