mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
unittest: add some tests for get_relative_path helper
v2: let's also mock kerndat_s.sysctl_nr_open field, to make aarch64 clang ci happy Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
parent
97bd9511ca
commit
9d1f39f28a
3 changed files with 83 additions and 0 deletions
|
|
@ -87,6 +87,7 @@ $(obj)/criu: $(PROGRAM-BUILTINS)
|
|||
$(call msg-link, $@)
|
||||
$(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(WRAPFLAGS) $(LDFLAGS) $(GMONLDOPT) -rdynamic -o $@
|
||||
|
||||
UNIT-BUILTINS += $(obj)/util.o
|
||||
UNIT-BUILTINS += $(obj)/config.o
|
||||
UNIT-BUILTINS += $(obj)/log.o
|
||||
UNIT-BUILTINS += $(obj)/string.o
|
||||
|
|
|
|||
|
|
@ -97,3 +97,42 @@ int close_service_fd(int type)
|
|||
void compel_log_init(int log_fn, unsigned int level)
|
||||
{
|
||||
}
|
||||
|
||||
void set_cr_errno(int new_err)
|
||||
{
|
||||
}
|
||||
|
||||
struct ns_desc {
|
||||
};
|
||||
struct ns_desc user_ns_desc;
|
||||
int switch_ns(int pid, struct ns_desc *nd, int *rst)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
enum script_actions { ACT_FAKE };
|
||||
int run_scripts(enum script_actions act)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef struct VmaEntry VmaEntry;
|
||||
struct VmaEntry {
|
||||
};
|
||||
void vma_entry__init(VmaEntry *message)
|
||||
{
|
||||
}
|
||||
|
||||
int clone_noasan(int (*fn)(void *), int flags, void *arg)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct kerndat_s {
|
||||
unsigned int sysctl_nr_open;
|
||||
};
|
||||
struct kerndat_s kdat = {};
|
||||
|
||||
int service_fd_rlim_cur;
|
||||
|
||||
unsigned __page_size;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
#include "criu-log.h"
|
||||
|
||||
int parse_statement(int i, char *line, char **configuration);
|
||||
|
|
@ -100,6 +101,48 @@ int main(int argc, char *argv[], char *envp[])
|
|||
i = parse_statement(0, "a b c d e f g h i\n", configuration);
|
||||
assert(i == -1);
|
||||
|
||||
/* get_relative_path */
|
||||
/* different kinds of representation of "/" */
|
||||
assert(!strcmp(get_relative_path("/", "/"), ""));
|
||||
assert(!strcmp(get_relative_path("/", ""), ""));
|
||||
assert(!strcmp(get_relative_path("", "/"), ""));
|
||||
assert(!strcmp(get_relative_path(".", "/"), ""));
|
||||
assert(!strcmp(get_relative_path("/", "."), ""));
|
||||
assert(!strcmp(get_relative_path("/", "./"), ""));
|
||||
assert(!strcmp(get_relative_path("./", "/"), ""));
|
||||
assert(!strcmp(get_relative_path("/.", "./"), ""));
|
||||
assert(!strcmp(get_relative_path("./", "/."), ""));
|
||||
assert(!strcmp(get_relative_path(".//////.", ""), ""));
|
||||
assert(!strcmp(get_relative_path("/./", ""), ""));
|
||||
|
||||
/* all relative paths given are assumed relative to "/" */
|
||||
assert(!strcmp(get_relative_path("/a/b/c", "a/b/c"), ""));
|
||||
|
||||
/* multiple slashes are ignored, only directory names matter */
|
||||
assert(!strcmp(get_relative_path("///alfa///beta///gamma///", "//alfa//beta//gamma//"), ""));
|
||||
|
||||
/* returned path is always relative */
|
||||
assert(!strcmp(get_relative_path("/a/b/c", "/"), "a/b/c"));
|
||||
assert(!strcmp(get_relative_path("/a/b/c", "/a/b"), "c"));
|
||||
|
||||
/* single dots supported */
|
||||
assert(!strcmp(get_relative_path("./a/b", "a/"), "b"));
|
||||
|
||||
/* double dots are partially supported */
|
||||
assert(!strcmp(get_relative_path("a/../b", "a"), "../b"));
|
||||
assert(!strcmp(get_relative_path("a/../b", "a/.."), "b"));
|
||||
assert(!get_relative_path("a/../b/c", "b"));
|
||||
|
||||
/* if second path is not subpath - NULL returned */
|
||||
assert(!get_relative_path("/a/b/c", "/a/b/d"));
|
||||
assert(!get_relative_path("/a/b", "/a/b/c"));
|
||||
assert(!get_relative_path("/a/b/c/d", "b/c/d"));
|
||||
|
||||
assert(!strcmp(get_relative_path("./a////.///./b//././c", "///./a/b"), "c"));
|
||||
|
||||
/* leaves punctuation in returned string as is */
|
||||
assert(!strcmp(get_relative_path("./a////.///./b//././c", "a"), "b//././c"));
|
||||
|
||||
pr_msg("OK\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue