#!/bin/sh

export_top_env()
{
	export suite='kernel-selftests'
	export testcase='kernel-selftests'
	export category='functional'
	export kernel_cmdline='systemd.unified_cgroup_hierarchy=1'
	export job_origin='kernel-selftests-cgroup.yaml'
	export queue_cmdline_keys='branch
commit
kbuild_queue_analysis'
	export queue='validate'
	export testbox='lkp-csl-d01'
	export tbox_group='lkp-csl-d01'
	export job_file='/lkp/jobs/queued/validate/lkp-csl-d01/kernel-selftests-cgroup-debian-12-x86_64-20240206.cgz-930cb1423ee2-20241023-785310-z2v5p2-3.yaml'
	export id='f11a5e22e289a52a8f8714c70d702629576669d8'
	export queuer_version='/zday/lkp'
	export model='Cascade Lake'
	export nr_node=1
	export nr_cpu=36
	export memory='32G'
	export nr_ssd_partitions=1
	export ssd_partitions='/dev/disk/by-id/nvme-INTEL_SSDPEKNW010T8_PHNH119301NW1P0B-part3'
	export rootfs_partition='/dev/disk/by-id/nvme-INTEL_SSDPEKNW010T8_PHNH119301NW1P0B-part4'
	export brand='Intel(R) Core(TM) i9-10980XE CPU @ 3.00GHz'
	export commit='930cb1423ee2522760ffde43455b14df5c0d5487'
	export netconsole_port=6685
	export ucode='0x5003604'
	export need_kernel_version=
	export need_kconfig='{"BLOCK"=>"y"}
{"BTRFS_FS"=>"m"}
{"EFI"=>"y"}
EFIVAR_FS
{"FTRACE"=>"y"}
{"IP_ADVANCED_ROUTER"=>"y"}
{"IP_MULTIPLE_TABLES"=>"y"}
RC_CORE
{"RC_DECODERS"=>"y"}
{"RC_DEVICES"=>"y"}
{"RC_LOOPBACK"=>"m"}
{"RUNTIME_TESTING_MENU"=>"y"}
{"STAGING"=>"y"}
{"SYNC_FILE"=>"y"}
TEST_FIRMWARE
{"TEST_KMOD"=>"m"}
{"TEST_LKM"=>"m"}
TEST_USER_COPY
{"TUN"=>"m"}
{"XFS_FS"=>"m"}
OVERLAY_FS
{"PERF_EVENTS"=>"y"}
{"SCHED_DEBUG"=>"y"}
{"SHMEM"=>"y"}
{"TMPFS_XATTR"=>"y"}
{"TMPFS"=>"y"}'
	export initrds='linux_headers
linux_selftests'
	export kconfig='x86_64-rhel-8.3-kselftests'
	export enqueue_time='2024-10-23 20:41:54 +0800'
	export _rt='/result/kernel-selftests/cgroup/lkp-csl-d01/debian-12-x86_64-20240206.cgz/x86_64-rhel-8.3-kselftests/gcc-12/930cb1423ee2522760ffde43455b14df5c0d5487'
	export compiler='gcc-12'
	export head_commit='300f1ec94e891720b3eab16e9ff6f5e7fd22d873'
	export base_commit='8e929cb546ee42c9a61d24fae60605e9e3192354'
	export branch='linux-review/Lorenzo-Stoakes/pidfd-extend-pidfd_get_pid-and-de-duplicate-pid-lookup/20241018-050825'
	export rootfs='debian-12-x86_64-20240206.cgz'
	export user='lkp'
	export LKP_SERVER='internal-lkp-server'
	export scheduler_version='/lkp/lkp/.src-20241021-113231'
	export arch='x86_64'
	export max_uptime=6000
	export initrd='/osimage/debian/debian-12-x86_64-20240206.cgz'
	export bootloader_append='root=/dev/ram0
RESULT_ROOT=/result/kernel-selftests/cgroup/lkp-csl-d01/debian-12-x86_64-20240206.cgz/x86_64-rhel-8.3-kselftests/gcc-12/930cb1423ee2522760ffde43455b14df5c0d5487/3
BOOT_IMAGE=/pkg/linux/x86_64-rhel-8.3-kselftests/gcc-12/930cb1423ee2522760ffde43455b14df5c0d5487/vmlinuz-6.12.0-rc3-00009-g930cb1423ee2
branch=linux-review/Lorenzo-Stoakes/pidfd-extend-pidfd_get_pid-and-de-duplicate-pid-lookup/20241018-050825
job=/lkp/jobs/scheduled/lkp-csl-d01/kernel-selftests-cgroup-debian-12-x86_64-20240206.cgz-930cb1423ee2-20241023-785310-z2v5p2-3.yaml
user=lkp
ARCH=x86_64
kconfig=x86_64-rhel-8.3-kselftests
commit=930cb1423ee2522760ffde43455b14df5c0d5487
systemd.unified_cgroup_hierarchy=1
intremap=posted_msi
max_uptime=6000
LKP_SERVER=internal-lkp-server
nokaslr
selinux=0
debug
apic=debug
sysrq_always_enabled
rcupdate.rcu_cpu_stall_timeout=100
net.ifnames=0
printk.devkmsg=on
panic=-1
softlockup_panic=1
nmi_watchdog=panic
oops=panic
load_ramdisk=2
prompt_ramdisk=0
drbd.minor_count=8
systemd.log_level=err
ignore_loglevel
console=tty0
earlyprintk=ttyS0,115200
console=ttyS0,115200
vga=normal
rw'
	export modules_initrd='/pkg/linux/x86_64-rhel-8.3-kselftests/gcc-12/930cb1423ee2522760ffde43455b14df5c0d5487/modules.cgz'
	export linux_headers_initrd='/pkg/linux/x86_64-rhel-8.3-kselftests/gcc-12/930cb1423ee2522760ffde43455b14df5c0d5487/linux-headers.cgz'
	export linux_selftests_initrd='/pkg/linux/x86_64-rhel-8.3-kselftests/gcc-12/930cb1423ee2522760ffde43455b14df5c0d5487/linux-selftests.cgz'
	export bm_initrd='/osimage/deps/debian-12-x86_64-20240206.cgz/run-ipconfig_20240904.cgz,/osimage/deps/debian-12-x86_64-20240206.cgz/lkp_20240216.cgz,/osimage/deps/debian-12-x86_64-20240206.cgz/rsync-rootfs_20240301.cgz,/osimage/deps/debian-12-x86_64-20240206.cgz/kernel-selftests_20240508.cgz,/osimage/pkg/debian-12-x86_64-20240206.cgz/kernel-selftests-x86_64-977d51cf-1_20240508.cgz,/osimage/deps/debian-12-x86_64-20240206.cgz/hw_20240216.cgz'
	export ucode_initrd='/osimage/ucode/intel-ucode-20230906.cgz'
	export lkp_initrd='/osimage/user/lkp/lkp-x86_64.cgz'
	export site='inn'
	export LKP_CGI_PORT=80
	export LKP_CIFS_PORT=139
	export job_initrd='/lkp/jobs/scheduled/lkp-csl-d01/kernel-selftests-cgroup-debian-12-x86_64-20240206.cgz-930cb1423ee2-20241023-785310-z2v5p2-3.cgz'
	export last_kernel='5.13.0-rc1'
	export repeat_to=6
	export kbuild_queue_analysis=1
	export kernel='/pkg/linux/x86_64-rhel-8.3-kselftests/gcc-12/930cb1423ee2522760ffde43455b14df5c0d5487/vmlinuz-6.12.0-rc3-00009-g930cb1423ee2'
	export result_root='/result/kernel-selftests/cgroup/lkp-csl-d01/debian-12-x86_64-20240206.cgz/x86_64-rhel-8.3-kselftests/gcc-12/930cb1423ee2522760ffde43455b14df5c0d5487/3'

	[ -n "$LKP_SRC" ] ||
	export LKP_SRC=/lkp/${user:-lkp}/src
}

run_job()
{
	echo $$ > $TMP/run-job.pid

	. $LKP_SRC/lib/http.sh
	. $LKP_SRC/lib/job.sh
	. $LKP_SRC/lib/env.sh

	export_top_env

	run_setup $LKP_SRC/setup/sanity-check

	run_monitor ignored=1 $LKP_SRC/monitors/wrapper oom-killer
	run_monitor $LKP_SRC/monitors/wrapper kmsg
	run_monitor $LKP_SRC/monitors/wrapper heartbeat
	run_monitor $LKP_SRC/monitors/wrapper meminfo
	run_monitor $LKP_SRC/monitors/plain/watchdog

	run_test group='cgroup' $LKP_SRC/tests/wrapper kernel-selftests
}

extract_stats()
{
	export stats_part_begin=
	export stats_part_end=

	env group='cgroup' $LKP_SRC/stats/wrapper kernel-selftests
	$LKP_SRC/stats/wrapper kmsg
	$LKP_SRC/stats/wrapper meminfo

	$LKP_SRC/stats/wrapper time kernel-selftests.time
	$LKP_SRC/stats/wrapper dmesg
	$LKP_SRC/stats/wrapper kmsg
	$LKP_SRC/stats/wrapper last_state
	$LKP_SRC/stats/wrapper stderr
	$LKP_SRC/stats/wrapper time
}

"$@"