The problem with the unit tests not being run (especially on Github) appears to be the result of compiler optimizations.
Fix this by disabling compiler optimizations in the mock functions and add appropriate commetns explaining this.
Do not wrap/mock strncmp() and strnlen().
The directory tests are now completed.
# Therefore, this file is a work-around to inject the mocks into the library for testing purposes.
# This should exactly match the "settings" file, except for the additional "-Wl,--wrap" parts and the additional mock source file.
#
+# The flags -o0 must be passed to prevent the compiler from optimizing away any functions being mocked (which results in the mock not happening and a real function being called).
+# Alternatively, figure out which optimization that is disabled by -o0 and have that specific optimization disabled.
+#
build_name f_account
search_shared yes
search_static yes
-flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
+flags -O0 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
flags-clang -Wno-logical-op-parentheses
flags-test -fstack-protector
# Therefore, this file is a work-around to inject the mocks into the library for testing purposes.
# This should exactly match the "settings" file, except for the additional "-Wl,--wrap" parts and the additional mock source file.
#
+# The flags -o0 must be passed to prevent the compiler from optimizing away any functions being mocked (which results in the mock not happening and a real function being called).
+# Alternatively, figure out which optimization that is disabled by -o0 and have that specific optimization disabled.
+#
build_name f_capability
#defines -D_di_libcap_
defines -D_libcap_legacy_only_
-flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
+flags -O0 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
flags-clang -Wno-logical-op-parentheses
flags-test -fstack-protector
# Therefore, this file is a work-around to inject the mocks into the library for testing purposes.
# This should exactly match the "settings" file, except for the additional "-Wl,--wrap" parts and the additional mock source file.
#
+# The flags -o0 must be passed to prevent the compiler from optimizing away any functions being mocked (which results in the mock not happening and a real function being called).
+# Alternatively, figure out which optimization that is disabled by -o0 and have that specific optimization disabled.
+#
build_name f_color
search_shared yes
search_static yes
-flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
+flags -O0 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
flags-clang -Wno-logical-op-parentheses
flags-test -fstack-protector
flags_library -fPIC
# Therefore, this file is a work-around to inject the mocks into the library for testing purposes.
# This should exactly match the "settings" file, except for the additional "-Wl,--wrap" parts and the additional mock source file.
#
+# The flags -o0 must be passed to prevent the compiler from optimizing away any functions being mocked (which results in the mock not happening and a real function being called).
+# Alternatively, figure out which optimization that is disabled by -o0 and have that specific optimization disabled.
+#
build_name f_conversion
search_shared yes
search_static yes
-flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
+flags -O0 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
flags-clang -Wno-logical-op-parentheses
flags-test -fstack-protector
# Therefore, this file is a work-around to inject the mocks into the library for testing purposes.
# This should exactly match the "settings" file, except for the additional "-Wl,--wrap" parts and the additional mock source file.
#
+# The flags -o0 must be passed to prevent the compiler from optimizing away any functions being mocked (which results in the mock not happening and a real function being called).
+# Alternatively, figure out which optimization that is disabled by -o0 and have that specific optimization disabled.
+#
build_name f_directory
search_shared yes
search_static yes
-flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
+flags -O0 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
flags-clang -Wno-logical-op-parentheses
flags-test -fstack-protector
flags -Wl,--wrap=remove
flags -Wl,--wrap=scandir
flags -Wl,--wrap=stat
-flags -Wl,--wrap=strncmp
-flags -Wl,--wrap=strnlen
flags -Wl,--wrap=utimensat
flags -Wl,--wrap=versionsort
return -1;
}
+ struct stat * const mocked_stat = mock_type(struct stat *);
+
+ statbuf->st_dev = mocked_stat->st_dev;
+ statbuf->st_ino = mocked_stat->st_ino;
+ statbuf->st_mode = mocked_stat->st_mode;
+ statbuf->st_nlink = mocked_stat->st_nlink;
+ statbuf->st_uid = mocked_stat->st_uid;
+ statbuf->st_gid = mocked_stat->st_gid;
+ statbuf->st_rdev = mocked_stat->st_rdev;
+ statbuf->st_size = mocked_stat->st_size;
+ statbuf->st_blksize = mocked_stat->st_blksize;
+ statbuf->st_blocks = mocked_stat->st_blocks;
+ statbuf->st_atime = mocked_stat->st_atime;
+ statbuf->st_mtime = mocked_stat->st_mtime;
+ statbuf->st_ctime = mocked_stat->st_ctime;
+
return mock_type(int);
}
for (int i = 0; i < 10; ++i) {
- will_return(__wrap_stat, true);
- will_return(__wrap_stat, errnos[i]);
+ will_return(__wrap_fstatat, true);
+ will_return(__wrap_fstatat, errnos[i]);
const f_status_t status = f_directory_exists_at(0, path, 0);
memset(&statistics, 0, sizeof (struct stat));
{
- will_return(__wrap_stat, false);
- will_return(__wrap_stat, &statistics);
- will_return(__wrap_stat, 0);
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
const f_status_t status = f_directory_exists_at(0, path, 0);
statistics.st_mode = 1 | S_IFDIR;
{
- will_return(__wrap_stat, false);
- will_return(__wrap_stat, &statistics);
- will_return(__wrap_stat, 0);
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
const f_status_t status = f_directory_exists_at(0, path, 0);
int errnos[] = {
EACCES,
EFAULT,
+ ELOOP,
ENAMETOOLONG,
ENOENT,
ENOMEM,
F_file_stat,
};
- for (int i = 0; i < 8; ++i) {
+ for (int i = 0; i < 9; ++i) {
will_return(__wrap_stat, true);
will_return(__wrap_stat, errnos[i]);
for (int i = 0; i < 10; ++i) {
- will_return(__wrap_stat, true);
- will_return(__wrap_stat, errnos[i]);
+ will_return(__wrap_fstatat, true);
+ will_return(__wrap_fstatat, errnos[i]);
const f_status_t status = f_directory_is_at(0, path, 0);
memset(&statistics, 0, sizeof (struct stat));
{
- will_return(__wrap_stat, false);
- will_return(__wrap_stat, &statistics);
- will_return(__wrap_stat, 0);
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
const f_status_t status = f_directory_is_at(0, path, 0);
statistics.st_mode = 1 | S_IFDIR;
{
- will_return(__wrap_stat, false);
- will_return(__wrap_stat, &statistics);
- will_return(__wrap_stat, 0);
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
const f_status_t status = f_directory_is_at(0, path, 0);
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
{
+ // The scandir() allocates the entire struct dirent.
+ struct dirent **directories = (struct dirent **) malloc(sizeof(struct dirent *));
+
+ memset(directories, 0, sizeof(struct dirent *));
+
will_return(__wrap_scandir, false);
+ will_return(__wrap_scandir, directories);
will_return(__wrap_scandir, 0);
const f_status_t status = f_directory_list(path, 0, 0, &names);
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
{
- struct dirent directory;
- memset(&directory, 0, sizeof(struct dirent));
-
- struct dirent directories[2];
+ // The scandir() allocates the entire struct dirent.
+ struct dirent **directories = (struct dirent **) malloc(sizeof(struct dirent *));
- memset(directories, 0, sizeof(struct dirent) * 2);
+ directories[0] = (struct dirent *) malloc(sizeof(struct dirent));
- directories[0] = directory;
+ memset(directories[0], 0, sizeof(struct dirent));
+ memcpy(directories[0]->d_name, path.string, sizeof(f_char_t) * path.used);
+ directories[0]->d_name[path.used] = 0;
will_return(__wrap_scandir, false);
- will_return(__wrap_scandir, &directories);
- will_return(__wrap_strnlen, 1);
- will_return(__wrap_strncmp, 1);
- will_return(__wrap_strncmp, 1);
+ will_return(__wrap_scandir, directories);
+ will_return(__wrap_scandir, 1);
const f_status_t status = f_directory_list(path, 0, 0, &names);
F_memory_not,
F_directory_not,
F_number_overflow,
- F_failure,
+ F_file_stat,
};
for (int i = 0; i < 8; ++i) {
F_failure,
};
+ struct stat statistics;
+
+ memset(&statistics, 0, sizeof (struct stat));
+
+ statistics.st_mode = 1 | S_IFDIR;
+
for (int i = 0; i < 12; ++i) {
- will_return(__wrap_mkdir, false);
- will_return(__wrap_mkdir, 0);
+ will_return(__wrap_stat, false);
+ will_return(__wrap_stat, &statistics);
+ will_return(__wrap_stat, 0);
will_return(__wrap_utimensat, true);
will_return(__wrap_utimensat, errnos[i]);
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
{
- will_return(__wrap_mkdir, false);
- will_return(__wrap_mkdir, 0);
- will_return(__wrap_utimensat, false);
- will_return(__wrap_utimensat, 0);
+ struct stat statistics;
+
+ memset(&statistics, 0, sizeof (struct stat));
+
+ statistics.st_mode = 1 | S_IFDIR;
+
+ will_return(__wrap_stat, false);
+ will_return(__wrap_stat, &statistics);
+ will_return(__wrap_stat, 0);
+ will_return(__wrap_utimensat, false);
+ will_return(__wrap_utimensat, 0);
const f_status_t status = f_directory_touch(path, 0);
}
{
- will_return(__wrap_mkdir, true);
- will_return(__wrap_mkdir, ENOENT);
- will_return(__wrap_mkdir, false);
- will_return(__wrap_mkdir, 0);
+ will_return(__wrap_stat, true);
+ will_return(__wrap_stat, ENOENT);
+ will_return(__wrap_mkdir, false);
+ will_return(__wrap_mkdir, 0);
const f_status_t status = f_directory_touch(path, 0);
F_memory_not,
F_directory_not,
F_number_overflow,
- F_failure,
+ F_file_stat,
};
for (int i = 0; i < 8; ++i) {
- will_return(__wrap_stat, true);
- will_return(__wrap_stat, errnos[i]);
+ will_return(__wrap_fstatat, true);
+ will_return(__wrap_fstatat, errnos[i]);
const f_status_t status = f_directory_touch_at(1, path, 0, 0);
for (int i = 0; i < 15; ++i) {
- will_return(__wrap_stat, true);
- will_return(__wrap_stat, ENOENT);
- will_return(__wrap_mkdir, true);
- will_return(__wrap_mkdir, errnos[i]);
+ will_return(__wrap_fstatat, true);
+ will_return(__wrap_fstatat, ENOENT);
+ will_return(__wrap_mkdirat, true);
+ will_return(__wrap_mkdirat, errnos[i]);
const f_status_t status = f_directory_touch_at(1, path, 0, 0);
F_failure,
};
+ struct stat statistics;
+
+ memset(&statistics, 0, sizeof (struct stat));
+
+ statistics.st_mode = 1 | S_IFDIR;
+
for (int i = 0; i < 12; ++i) {
- will_return(__wrap_mkdir, false);
- will_return(__wrap_mkdir, 0);
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
will_return(__wrap_utimensat, true);
will_return(__wrap_utimensat, errnos[i]);
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
{
- will_return(__wrap_mkdir, false);
- will_return(__wrap_mkdir, 0);
- will_return(__wrap_utimensat, false);
- will_return(__wrap_utimensat, 0);
+ struct stat statistics;
+
+ memset(&statistics, 0, sizeof (struct stat));
+
+ statistics.st_mode = 1 | S_IFDIR;
+
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
+ will_return(__wrap_utimensat, false);
+ will_return(__wrap_utimensat, 0);
const f_status_t status = f_directory_touch_at(1, path, 0, 0);
}
{
- will_return(__wrap_mkdir, true);
- will_return(__wrap_mkdir, ENOENT);
- will_return(__wrap_mkdir, false);
- will_return(__wrap_mkdir, 0);
+ will_return(__wrap_fstatat, true);
+ will_return(__wrap_fstatat, ENOENT);
+ will_return(__wrap_mkdirat, false);
+ will_return(__wrap_mkdirat, 0);
const f_status_t status = f_directory_touch_at(1, path, 0, 0);
cmocka_unit_test(test__f_directory_create_at__returns_data_not),
cmocka_unit_test(test__f_directory_create_at__works),
- // Unable to perform tests because stat() appears to not properly get mocked.
- //cmocka_unit_test(test__f_directory_exists__fails),
- //cmocka_unit_test(test__f_directory_exists__returns_data_not),
- //cmocka_unit_test(test__f_directory_exists__returns_false),
- //cmocka_unit_test(test__f_directory_exists__returns_true),
-
- // Unable to perform tests because stat() appears to not properly get mocked.
- //cmocka_unit_test(test__f_directory_exists_at__fails),
- //cmocka_unit_test(test__f_directory_exists_at__returns_data_not),
- //cmocka_unit_test(test__f_directory_exists_at__returns_false),
- //cmocka_unit_test(test__f_directory_exists_at__returns_true),
-
- // Unable to perform tests because stat() appears to not properly get mocked.
- //cmocka_unit_test(test__f_directory_is__fails),
- //cmocka_unit_test(test__f_directory_is__returns_data_not),
- //cmocka_unit_test(test__f_directory_is__returns_false),
- //cmocka_unit_test(test__f_directory_is__returns_true),
-
- // Unable to perform tests because stat() appears to not properly get mocked.
- //cmocka_unit_test(test__f_directory_is_at__fails),
- //cmocka_unit_test(test__f_directory_is_at__returns_data_not),
- //cmocka_unit_test(test__f_directory_is_at__returns_false),
- //cmocka_unit_test(test__f_directory_is_at__returns_true),
-
- // Unable to perform tests because scandir() appears to not properly get mocked.
- //cmocka_unit_test(test__f_directory_list__fails),
- //cmocka_unit_test(test__f_directory_list__returns_data_not),
- //cmocka_unit_test(test__f_directory_list__returns_directory_empty),
- //cmocka_unit_test(test__f_directory_list__works),
+ cmocka_unit_test(test__f_directory_exists__fails),
+ cmocka_unit_test(test__f_directory_exists__returns_data_not),
+ cmocka_unit_test(test__f_directory_exists__returns_false),
+ cmocka_unit_test(test__f_directory_exists__returns_true),
+
+ cmocka_unit_test(test__f_directory_exists_at__fails),
+ cmocka_unit_test(test__f_directory_exists_at__returns_data_not),
+ cmocka_unit_test(test__f_directory_exists_at__returns_false),
+ cmocka_unit_test(test__f_directory_exists_at__returns_true),
+
+ cmocka_unit_test(test__f_directory_is__fails),
+ cmocka_unit_test(test__f_directory_is__returns_data_not),
+ cmocka_unit_test(test__f_directory_is__returns_false),
+ cmocka_unit_test(test__f_directory_is__returns_true),
+
+ cmocka_unit_test(test__f_directory_is_at__fails),
+ cmocka_unit_test(test__f_directory_is_at__returns_data_not),
+ cmocka_unit_test(test__f_directory_is_at__returns_false),
+ cmocka_unit_test(test__f_directory_is_at__returns_true),
+
+ cmocka_unit_test(test__f_directory_list__fails),
+ cmocka_unit_test(test__f_directory_list__returns_data_not),
+ cmocka_unit_test(test__f_directory_list__returns_directory_empty),
+ cmocka_unit_test(test__f_directory_list__works),
cmocka_unit_test(test__f_directory_open__fails),
cmocka_unit_test(test__f_directory_open__returns_data_not),
cmocka_unit_test(test__f_directory_remove_custom__returns_data_not),
cmocka_unit_test(test__f_directory_remove_custom__works),
- // Unable to perform tests because stat() appears to not properly get mocked.
- //cmocka_unit_test(test__f_directory_touch__fails),
- //cmocka_unit_test(test__f_directory_touch__returns_data_not),
- //cmocka_unit_test(test__f_directory_touch__works),
+ cmocka_unit_test(test__f_directory_touch__fails),
+ cmocka_unit_test(test__f_directory_touch__returns_data_not),
+ cmocka_unit_test(test__f_directory_touch__works),
- // Unable to perform tests because stat() appears to not properly get mocked.
- //cmocka_unit_test(test__f_directory_touch_at__fails),
- //cmocka_unit_test(test__f_directory_touch_at__returns_data_not),
- //cmocka_unit_test(test__f_directory_touch_at__works),
+ cmocka_unit_test(test__f_directory_touch_at__fails),
+ cmocka_unit_test(test__f_directory_touch_at__returns_data_not),
+ cmocka_unit_test(test__f_directory_touch_at__works),
#ifndef _di_level_0_parameter_checking_
// f_directory_create() doesn't use parameter checking.