summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorAbhishek Singh <abhishekkumarsingh.cse@gmail.com>2013-04-16 19:17:16 +0530
committerJakub Hrozek <jhrozek@redhat.com>2013-05-02 20:12:41 +0200
commit25255e4d0e1517a5d443e8fee22e91862e255702 (patch)
tree2d418e5b0683d496695989b8cdd7e893d281ebc8 /src/tests
parent9a0255c508ede92423a1f8a02c6c38328482c55f (diff)
downloadsssd-25255e4d0e1517a5d443e8fee22e91862e255702.tar.gz
sssd-25255e4d0e1517a5d443e8fee22e91862e255702.tar.xz
sssd-25255e4d0e1517a5d443e8fee22e91862e255702.zip
Fix segmentation fault in test_io.
tests_set_cwd is used and relativepath calculation method is changed and is made general based on basedir.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/cmocka/test_io.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/tests/cmocka/test_io.c b/src/tests/cmocka/test_io.c
index 4d21b2e25..266f2ce93 100644
--- a/src/tests/cmocka/test_io.c
+++ b/src/tests/cmocka/test_io.c
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <fcntl.h>
+#include <errno.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
@@ -32,10 +33,12 @@
#include <cmocka.h>
#include <dirent.h>
#include <unistd.h>
+#include <libgen.h>
#include "limits.h"
#include "util/io.h"
#include "util/util.h"
+#include "tests/common.h"
#define FILE_PATH TEST_DIR"/test_io.XXXXXX"
#define NON_EX_PATH "non-existent-path"
@@ -49,8 +52,11 @@ static char *get_filepath(char path[])
ret = mkstemp(path);
if (ret == -1) {
- fprintf(stderr, "mkstemp failed\n");
+ int err = errno;
+ fprintf(stderr, "mkstemp failed with path:'%s' [%s]\n",
+ path, strerror(err));
}
+ assert_false(ret == -1);
return path;
}
@@ -58,9 +64,13 @@ static char *get_filepath(char path[])
void setup_dirp(void **state)
{
DIR *dirp = opendir(TEST_DIR);
- if (dirp != NULL){
- *state = (void *)dirp;
+ if (dirp == NULL) {
+ int err = errno;
+ fprintf(stderr, "Could not open directory:'%s' [%s]\n",
+ TEST_DIR, strerror(err));
}
+ assert_non_null(dirp);
+ *state = (void *)dirp;
}
void teardown_dirp(void **state)
@@ -111,11 +121,15 @@ void test_sss_openat_cloexec_success(void **state)
int dir_fd;
int flags = O_RDWR;
char path[PATH_MAX] = {'\0'};
+ char *basec;
const char *relativepath;
- relativepath = strchr(get_filepath(path), 't');
dir_fd = dirfd((DIR *)*state);
+ basec = strdup(get_filepath(path));
+ assert_non_null(basec);
+ relativepath = basename(basec);
fd = sss_openat_cloexec(dir_fd, relativepath, flags, &ret);
+ free(basec);
assert_true(fd != -1);
ret_flag = fcntl(fd, F_GETFD, 0);
@@ -153,5 +167,6 @@ int main(void)
teardown_dirp)
};
+ tests_set_cwd();
return run_tests(tests);
}