Skip to content

Commit c8dc7e6

Browse files
Roman Rashchupkinpaboldin
Roman Rashchupkin
authored andcommitted
Add --test stage to pkgbuild
Signed-off-by: Roman Rashchupkin <rrashchupkin@cloudlinux.com>
1 parent c9ae970 commit c8dc7e6

File tree

5 files changed

+126
-50
lines changed

5 files changed

+126
-50
lines changed

packages/rhel7/glibc/glibc-2.17-55.el7/info

+14-22
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,6 @@ kp_build_hook() {
5555
$KP_PROJECT_BUILD_ROOT/SPECS/$KP_PROJECT_SPEC
5656
}
5757

58-
# Replace patch build results with original libraries for testing
59-
_install_originals() {
60-
eval set -- $KP_INSTALL_FILES
61-
while test -n "$1"; do
62-
local buildpath="$1"
63-
local installpath="$2"
64-
shift 2
65-
66-
if test "$installpath" = "IGNORE"; then
67-
continue
68-
fi
69-
70-
/bin/cp -r /root/root.original/$installpath $KP_PROJECT_BUILD_DIR/$buildpath
71-
done
72-
}
7358

7459
_run_tests() {
7560
if test -f $LIBCARE_DIR/execve/execve.so; then
@@ -113,15 +98,22 @@ _run_tests() {
11398
export PATH=$KCPATH
11499
}
115100

116-
kp_patch_test() {
117-
_install_originals
101+
kp_prepare_test_binaries() {
102+
# Replace patch build results with original libraries for testing
103+
kp_install_files /root/root.original \
104+
$KP_PROJECT_BUILD_DIR \
105+
"to_prebuild" \
106+
"$KP_INSTALL_FILES"
107+
}
118108

109+
kp_patch_test() {
119110
rm -f /var/run/libcare.sock
120111

121-
PATCH_ROOT=/root/${KP_PROJECT_PATCH%.*}
112+
PATCH_ROOT=$KP_PROJECT_BUILD_ROOT/storage
122113
$KPATCH_PATH/libcare-ctl -v server /var/run/libcare.sock $PATCH_ROOT \
123-
>/data/test.log 2>&1 & :
114+
>/data/libcare-ctl.log 2>&1 & :
124115
LISTENER_PID=$!
116+
125117
sleep 1
126118
kill -0 $LISTENER_PID
127119

@@ -134,11 +126,11 @@ kp_patch_test() {
134126

135127
popd
136128

137-
local patched=$(awk '/kpatch_ctl targeting/ { n++ } END { print n }' /data/test.log)
129+
local patched=$(awk '/kpatch_ctl targeting/ { n++ } END { print n }' /data/libcare-ctl.log)
138130

139131
test $patched -ge $executed
140132

141-
grep -vq 'No patch(es) applicable to' /data/test.log
142-
grep 'patch hunk(s) have been successfully applied' /data/test.log \
133+
grep -vq 'No patch(es) applicable to' /data/libcare-ctl.log
134+
grep 'patch hunk(s) have been successfully applied' /data/libcare-ctl.log \
143135
| wc -l
144136
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
image: kernelcare/centos7:gcc-4.8.2-16.el7
22
prebuild: /tmp/build.orig-glibc-2.17-55.el7.x86_64.rpm.tgz
3+
patch: /tmp/kpatch-glibc-2.17-55.el7.x86_64.tgz
34
input:
45
- package: .
56
- patches: ../../../../patches/

scripts/pkgbuild

+68-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ die() {
1717
usage() {
1818
echo "Usage: build [--prebuild] [--help] [--arch ARCH] DIR"
1919
echo " -p|--prebuild prebuild project for further use"
20+
echo " -t|--test run unit and stress tests"
2021
echo " -a|--arch ARCH target architecture(x86_64 by default)"
2122
echo " -h|--help print this message"
2223
echo " DIR directory with project's info file and other resources"
@@ -32,6 +33,9 @@ prepare() {
3233
-p|--prebuild)
3334
ACTION=prebuild
3435
;;
36+
-t|--test)
37+
ACTION=test
38+
;;
3539
-a|--arch)
3640
shift
3741
ARCH=$1
@@ -247,13 +251,17 @@ kp_build_rpm() {
247251
-bc \
248252
$KP_RPMBUILD_FLAGS \
249253
'--define "_topdir $KP_PROJECT_BUILD_ROOT"' \
250-
$KP_PROJECT_BUILD_ROOT/SPECS/$KP_PROJECT_SPEC
254+
$KP_PROJECT_BUILD_ROOT/SPECS/$KP_PROJECT_SPEC 2>&1 |
255+
tee $KP_PROJECT_BUILD_ROOT/build.log
251256
}
252257

253-
kp_install_generic() {
254-
local ROOT_PATCHED="$HOME/root.patched"
258+
kp_install_files() {
259+
local src="$1"
260+
local dest="$2"
261+
local direction="$3"
262+
local files="$4"
255263

256-
eval set -- $KP_INSTALL_FILES
264+
eval set -- $files
257265
while test -n "$1"; do
258266
local buildpath="$1"
259267
local installpath="$2"
@@ -263,12 +271,16 @@ kp_install_generic() {
263271
continue
264272
fi
265273

266-
installpath="$ROOT_PATCHED/$installpath"
267-
268-
mkdir -p "$(dirname "$installpath")"
269-
270-
/bin/cp -ra $KP_PROJECT_BUILD_DIR/$buildpath $installpath
274+
if test $direction = "from_prebuild"; then
275+
install -D $src/$buildpath $dest/$installpath
276+
else
277+
install -D $src/$installpath $dest/$buildpath
278+
fi
271279
done
280+
}
281+
282+
kp_check_missing_files() {
283+
local builddir="$1"
272284

273285
local failed=
274286
pushd $KP_PROJECT_BUILD_DIR
@@ -295,6 +307,16 @@ kp_install_generic() {
295307
fi
296308
}
297309

310+
kp_install_generic() {
311+
local root_patched="$HOME/root.patched"
312+
313+
kp_install_files $KP_PROJECT_BUILD_DIR \
314+
$root_patched \
315+
"from_prebuild" \
316+
"$KP_INSTALL_FILES"
317+
kp_check_missing_files $KP_PROJECT_BUILD_DIR
318+
}
319+
298320
kp_install_rpm() {
299321
kp_install_orig_rpm
300322
kp_install_generic
@@ -367,6 +389,33 @@ kp_pack_patch() {
367389
popd
368390
}
369391

392+
kp_unpack_patch() {
393+
local tmpdir=$(mktemp -d --tmpdir)
394+
395+
echo " unpacking patches for $KP_PROJECT into $KP_PROJECT_BUILD_ROOT/storage"
396+
397+
tar -xf /kcdata/$KP_PROJECT_PATCH -C $tmpdir
398+
399+
find $tmpdir -name \*.kpatch > $tmpdir/patchlist
400+
401+
while read patchfile; do
402+
local patchname=${patchfile##*/}
403+
local buildid=${patchname%.kpatch}
404+
405+
local KP_STORAGE=$KP_PROJECT_BUILD_ROOT/storage/$buildid
406+
407+
mkdir -p $KP_STORAGE/1
408+
cp $patchfile $KP_STORAGE/1/kpatch.bin
409+
ln -rs $KP_STORAGE/1 $KP_STORAGE/latest
410+
done < $tmpdir/patchlist
411+
412+
rm -fr $tmpdir
413+
}
414+
415+
kp_mark_tests_fail() {
416+
touch /kcdata/Tests-FAIL
417+
}
418+
370419
overwrite_utils() {
371420
TMPBIN=$(mktemp -d --tmpdir)
372421

@@ -394,7 +443,8 @@ overwrite_utils() {
394443
}
395444

396445
kp_patch_test() {
397-
:
446+
echo "Empty kp_patch_test called, override it!"
447+
exit 1
398448
}
399449

400450
main() {
@@ -408,20 +458,25 @@ main() {
408458

409459
kp_prepare_env_hook
410460

411-
if [ "$ACTION" == "prebuild" ]; then
461+
if test "$ACTION" == "prebuild"; then
412462
kp_prepare_source
413463
kp_prebuild_hook
414464
kp_prebuild
415465
kp_pack_prebuilt
416-
else
466+
elif test "$ACTION" == "build"; then
417467
kp_unpack_prebuilt
418468
kp_patch_source
419469
kp_build_hook
420470
kp_build
421471
kp_sanity_check
422472
kp_gen_kpatch
423-
kp_patch_test
424473
kp_pack_patch
474+
elif test "$ACTION" == "test"; then
475+
kp_unpack_prebuilt
476+
kp_prepare_test_binaries
477+
kp_unpack_patch
478+
#kp_patch_source
479+
kp_patch_test
425480
fi
426481

427482
#clean_dirs

scripts/toil/build-patch.sh

-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ make -C $KPATCH_PATH clean all
1515
make -C /data/execve clean all
1616

1717
/kcdata/scripts/pkgbuild $@ /kcdata/package
18-
ls /kcdata -lR

scripts/toil/pkgbuild.py

+43-14
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
first job.
1313
1414
#. `DoBuild` checks presence of the object in the Storage and runs
15-
`prebuildJob` chained with `uploadJob` and `buildJob` if the object is missing.
16-
Only `buildJob` is run otherwise.
15+
`prebuildJob` chained with `uploadPrebuildJob`, `buildJob`,
16+
`uploadPatchJob` and `testJob` if the object is missing.
17+
Only `buildJob` and it's children are run otherwise.
1718
1819
This is used to build missing parts such as an archive with the baseline
1920
source code called `prebuilt` which is listed as optional for the
@@ -625,7 +626,7 @@ def __init__(self, fileName, url):
625626
self.fileName = fileName
626627
super(S3DownloadJob, self).__init__(
627628
memory="1M", cores=1, unitName="download %s" % url,
628-
disk=self.obj['ContentLength'])
629+
disk=max(4096, self.obj['ContentLength']))
629630

630631
def run(self, fileStore):
631632
with fileStore.writeGlobalFileStream() as (fh, fileId):
@@ -731,24 +732,35 @@ class DoBuild(Job):
731732
"""If prebuild archive is not in storage do a prebuild and upload it to the
732733
specified location. Otherwise just do a build."""
733734

734-
def __init__(self, fileName, prebuildJob, uploadJob, buildJob):
735+
def __init__(self, prebuildFileName, buildFileName, prebuildJob, uploadPrebuildJob, buildJob, uploadPatchJob, testJob):
735736
super(DoBuild, self).__init__(memory="256M")
736737

737-
self.fileName = fileName
738+
self.prebuildFileName = prebuildFileName
739+
self.buildFileName = buildFileName
738740
self.prebuildJob = prebuildJob
739741
self.buildJob = buildJob
740-
self.uploadJob = uploadJob
742+
self.uploadPrebuildJob = uploadPrebuildJob
743+
self.uploadPatchJob = uploadPatchJob
744+
self.testJob = testJob
741745

742746
def run(self, fileStore):
743-
if self.fileName not in self.storage:
747+
if self.prebuildFileName not in self.storage:
744748
self.addChild(self.prebuildJob)
745749

746750
self.prebuildJob.addChildNoStorage(self.buildJob)
747-
self.prebuildJob.addChildNoStorage(self.uploadJob)
751+
self.prebuildJob.addChildNoStorage(self.uploadPrebuildJob)
752+
753+
self.buildJob.addChildNoStorage(self.uploadPatchJob)
754+
self.buildJob.addChildNoStorage(self.testJob)
748755
else:
749-
self.addChild(self.buildJob)
756+
if self.buildFileName not in self.storage:
757+
self.addChild(self.buildJob)
758+
self.buildJob.addChildNoStorage(self.uploadPatchJob)
759+
self.buildJob.addChildNoStorage(self.testJob)
760+
else:
761+
self.addChild(self.testJob)
750762

751-
self._storage = self.buildJob.storage
763+
self._storage = self.testJob.storage
752764

753765

754766
class BuildPatchJob(toilJob):
@@ -784,21 +796,33 @@ def run(self, fileStore):
784796
prebuildUrl = self.packageDescription['prebuild']
785797
prebuildName = os.path.basename(prebuildUrl)
786798

799+
patchUrl = self.packageDescription['patch']
800+
buildName = os.path.basename(patchUrl)
801+
787802
prebuildJob = DockerScriptJob(
788803
script=self.script,
789804
image=self.image,
790-
args=['-p'],
805+
args=['--prebuild'],
791806
logfileName="prebuild.log")
792-
uploadJob = UploadJob([(prebuildName, prebuildUrl)])
807+
uploadPrebuildJob = UploadJob([(prebuildName, prebuildUrl)])
808+
793809

794810
buildJob = DockerScriptJob(
795811
script=self.script,
796812
image=self.image,
797813
logfileName="build.log")
814+
uploadPatchJob = UploadJob([(buildName, patchUrl)])
798815

816+
testJob = DockerScriptJob(
817+
script=self.script,
818+
image=self.image,
819+
args=['--test'],
820+
logfileName="test.log")
821+
822+
doBuild = DoBuild(prebuildFileName=prebuildName, buildFileName=buildName, prebuildJob=prebuildJob,
823+
uploadPrebuildJob=uploadPrebuildJob, buildJob=buildJob,
824+
uploadPatchJob=uploadPatchJob, testJob=testJob)
799825

800-
doBuild = DoBuild(fileName=prebuildName, prebuildJob=prebuildJob,
801-
uploadJob=uploadJob, buildJob=buildJob)
802826
tail.addFollowOn(doBuild)
803827
tail = doBuild
804828

@@ -831,6 +855,11 @@ def readPackageDescription(packageFile):
831855
prebuildUrl = '*' + prebuildUrl
832856
inputs.append(prebuildUrl)
833857

858+
patchUrl = packageDescription['patch']
859+
if not patchUrl.startswith('*'):
860+
patchUrl = '*' + patchUrl
861+
inputs.append(patchUrl)
862+
834863
return packageDescription
835864

836865
def start(toil):

0 commit comments

Comments
 (0)