Skip to content

Commit

Permalink
Fix test by using an actual .so
Browse files Browse the repository at this point in the history
  • Loading branch information
lalten committed Oct 31, 2024
1 parent 304cbde commit 8b8633a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
4 changes: 2 additions & 2 deletions tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ appimage_test(
target_compatible_with = ["@platforms//os:linux"],
)

cc_binary(
cc_test(
name = "test_cc",
srcs = ["test.cc"],
copts = ["-std=c++20"],
env = {
"MY_APPIMAGE_ENV": "original",
"MY_BINARY_ENV": "not lost",
},
deps = ["//tests/relative_symlink_so:foo"]
deps = ["//tests/relative_symlink_so:libfoo"],
)

appimage_test(
Expand Down
30 changes: 19 additions & 11 deletions tests/relative_symlink_so/BUILD
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package(default_visibility = ["//tests:__subpackages__"])

cc_import(
name = "libfoo10",
shared_library = "libfoo.so.1.0",
genrule(
name = "make_libfoo",
srcs = ["foo.S"],
outs = ["libfoo.so.1", "libfoo.so"],
cmd = "\n".join([
"$(CC) -nostdlib -fPIC -shared -o $(RULEDIR)/libfoo.so.1 $<",
"$(STRIP) --strip-unneeded $(RULEDIR)/libfoo.so.1",
"ln -s libfoo.so.1 $(RULEDIR)/libfoo.so",
]),
toolchains=["@bazel_tools//tools/cpp:current_cc_toolchain"]
)

cc_import(
name = "libfoo1",
shared_library = "libfoo.so.1",
name = "libfoo_so",
shared_library = ":libfoo.so",
)

cc_import(
name = "libfoo",
shared_library = "libfoo.so",
name = "libfoo_so_1",
shared_library = ":libfoo.so.1",
)


cc_library(
name = "foo",
name = "libfoo",
deps = [
":libfoo",
":libfoo1",
":libfoo10",
":libfoo_so_1",
":libfoo_so",
],
alwayslink = True,
)
1 change: 1 addition & 0 deletions tests/relative_symlink_so/foo.S
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.section .text
1 change: 0 additions & 1 deletion tests/relative_symlink_so/libfoo.so

This file was deleted.

1 change: 0 additions & 1 deletion tests/relative_symlink_so/libfoo.so.1

This file was deleted.

Empty file.
24 changes: 14 additions & 10 deletions tests/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace fs = std::filesystem;
int main(int argc, char **argv, char **envp) {
(void)argc;
(void)argv;

int ret{EXIT_SUCCESS};

// Go through the environment variables and find the one we set in the BUILD.
// When running inside the appimage, we want the env to not be lost.
bool have_binary_env = false;
Expand All @@ -27,35 +30,36 @@ int main(int argc, char **argv, char **envp) {
}
if (!have_binary_env) {
std::cerr << "MY_BINARY_ENV not found or has wrong value" << std::endl;
return EXIT_FAILURE;
ret |= EXIT_FAILURE;
}
if (!have_appimage_env) {
std::cerr << "MY_APPIMAGE_ENV not found or has wrong value" << std::endl;
return EXIT_FAILURE;
ret |= EXIT_FAILURE;
}

// Check for broken symlinks
std::cout << "\n";
bool libfoo_found{false}; // Make sure the test "libfoo.so.1" exists
bool libfoo_found{false}; // Make sure the test "libfoo.*.so" exists
for (const auto &entry :
fs::recursive_directory_iterator(fs::current_path())) {
if (entry.path().filename() == "libfoo.so.1") {
if (entry.path().filename() == "libfoo.so") {
std::cout << "libfoo.so found" << std::endl;
libfoo_found = true;
}
if (fs::is_symlink(entry.path())) {
fs::path symlink_target = fs::read_symlink(entry.path());
std::cerr << entry.path() << " -> " << symlink_target;
if (!fs::exists(symlink_target)) {
std::cerr << "is broken" << std::endl;
return EXIT_FAILURE;
if (!fs::exists(entry.path().parent_path() / symlink_target)) {
std::cerr << " is broken" << std::endl;
ret |= EXIT_FAILURE;
}
std::cerr << std::endl;
}
}
if (!libfoo_found) {
std::cerr << "libfoo.so.1 not found" << std::endl;
return EXIT_FAILURE;
std::cerr << "libfoo.so not found" << std::endl;
ret |= EXIT_FAILURE;
}

return EXIT_SUCCESS;
return ret;
}

0 comments on commit 8b8633a

Please sign in to comment.