-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[antlir][rpm] add simple test in test_images/package
Summary: I'm discovering some more unexpected behaviors in `rpmbuild` that we need to make sure we're handling correctly. Add a basic test to install a binary and build an rpm In practice, this is already covered in `rpm.builder` tests, but the underlying antlir2 implementation should also be doing something reasonable. Test Plan: ``` ❯ buck2 test fbcode//mode/opt fbcode//antlir/antlir2/test_images/package/rpm:test Buck UI: https://www.internalfb.com/buck2/968c7345-75c7-407d-ac7c-4c4355e06626 Test UI: https://www.internalfb.com/intern/testinfra/testrun/6755399680156944 Network: Up: 0B Down: 0B (reSessionID-904c776d-1bb9-4c97-9a61-cb12b3dc69e0) Jobs completed: 9. Time elapsed: 3.7s. Cache hits: 0%. Commands: 2 (cached: 0, remote: 0, local: 2) Tests finished: Pass 1. Fail 0. Fatal 0. Skip 0. Build failure 0 ``` Reviewed By: epilatow Differential Revision: D65492077 fbshipit-source-id: 5e54e2cf2b7a80fb66301f28a5b30ccfcf7579a0
- Loading branch information
1 parent
c5b66d3
commit 3913a8b
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature") | ||
load("//antlir/antlir2/bzl/image:defs.bzl", "image") | ||
load("//antlir/antlir2/bzl/package:defs.bzl", "package") | ||
load("//antlir/antlir2/testing:image_test.bzl", "image_python_test") | ||
load("//antlir/bzl:build_defs.bzl", "cpp_binary", "cpp_library") | ||
|
||
oncall("antlir") | ||
|
||
cpp_library( | ||
# @autodeps-skip | ||
name = "libadd", | ||
srcs = ["add.c"], | ||
# the "main" SONAME is like a major version, there may be another point | ||
# release tacked on but anything with the same SONAME can be considered | ||
# fungible | ||
soname = "libadd.so.1", | ||
) | ||
|
||
cpp_binary( | ||
# @autodeps-skip | ||
name = "add", | ||
deps = [":libadd"], | ||
) | ||
|
||
image.layer( | ||
name = "layer", | ||
features = [ | ||
feature.ensure_dirs_exist(dirs = "/usr/bin"), | ||
feature.install( | ||
src = ":add", | ||
dst = "/usr/bin/add", | ||
never_use_dev_binary_symlink = True, | ||
), | ||
], | ||
) | ||
|
||
package.rpm( | ||
name = "add.rpm", | ||
# @oss-disable | ||
disable_strip = True, # disable double stripping (fixed later in this stack to not be necessary) | ||
layer = ":layer", | ||
license = "none", | ||
rpm_name = "add", | ||
) | ||
|
||
image.layer( | ||
name = "test-layer", | ||
features = [ | ||
feature.rpms_install(rpms = ["rpm"]), | ||
feature.install( | ||
src = ":add.rpm", | ||
dst = "/add.rpm", | ||
), | ||
], | ||
) | ||
|
||
image_python_test( | ||
name = "test", | ||
srcs = ["test.py"], | ||
# @oss-disable | ||
layer = ":test-layer", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
int add(int a, int b) { | ||
return a + b; | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
int a = atoi(argv[1]); | ||
int b = atoi(argv[2]); | ||
printf("%d + %d = %d\n", a, b, add(a, b)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import subprocess | ||
import unittest | ||
from os import PathLike | ||
from typing import Set | ||
|
||
|
||
def _files_in_rpm(rpm: PathLike) -> Set[str]: | ||
return set( | ||
subprocess.run( | ||
["rpm", "-qlp", rpm], check=True, capture_output=True, text=True | ||
).stdout.splitlines() | ||
) | ||
|
||
|
||
class RpmTest(unittest.TestCase): | ||
def test_stripped_binary(self): | ||
files = _files_in_rpm("/add.rpm") | ||
# The binary should be provided | ||
self.assertIn("/usr/bin/add", files) | ||
# It should also include debugging stuff, keyed by build-id | ||
self.assertIn("/usr/lib/.build-id", files) | ||
self.assertIn("/usr/lib/debug/.build-id", files) |