Skip to contentSkip to conversation

commands: add test for chrt

PATCH New Yihao Wu 2 participants 2 messages Jun 3, 2019 – Jun 5, 2019

lore
Share & tools
lore

Yihao Wu

author
#0 lore raw

PATCH 1/1 commands: add test for chrt

This test checks check whether chrt works properly

---
 runtest/commands                  |  1 +
 testcases/commands/chrt/Makefile  | 21 ++++++++++++++++
 testcases/commands/chrt/chrt01.sh | 52 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 testcases/commands/chrt/Makefile
 create mode 100755 testcases/commands/chrt/chrt01.sh
runtest/commands +1 -0
index ac15e8b..74bd860 100644
@@ -40,3 +40,4 @@ keyctl01_sh keyctl01.sh
 gdb01_sh gdb01.sh
 unshare01_sh unshare01.sh
 sysctl01_sh sysctl01.sh
+chrt01_sh chrt01.sh
testcases/commands/chrt/Makefile new file +21 -0
new file mode 100644
index 0000000..c6f931b
@@ -0,0 +1,21 @@
+#
+# Copyright (c) 2019 Alibaba Inc
+# Author: Yihao Wu <[email protected]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+# the GNU General Public License for more details.
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= chrt01.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/commands/chrt/chrt01.sh new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 commands: add test for chrt

Hi Yihao,

thanks for your patch.

First question: shouldn't this test go to upstream, i.e. libcg [1]?

BTW there are cgroup related tests which needs to get updated and rewritten to new API (testcases/kernel/controllers/cgroup*/).

Quoted 1 line

This test checks check whether chrt works properly

...

Quoted 6 lines

+++ b/testcases/commands/chrt/Makefile

testcases/commands/chrt/Makefile new file +3 -0
@@ -0,0 +1,21 @@
+#
+# Copyright (c) 2019 Alibaba Inc
+# Author: Yihao Wu <[email protected]>
 

testcases/commands/chrt/Makefile line 13

Quoted 10 lines
testcases/commands/chrt/Makefile new file +10 -0
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+# the GNU General Public License for more details.

Remove this GNU license text and use just
# SPDX-License-Identifier: GPL-2.0-or-later

...

Quoted 5 lines

+++ b/testcases/commands/chrt/chrt01.sh

testcases/commands/chrt/chrt01.sh new file +3 -0
@@ -0,0 +1,52 @@
+#!/bin/sh
+# Copyright (c) 2019 Alibaba Inc
+# Author: Yihao Wu <[email protected]>

testcases/commands/chrt/chrt01.sh line 13

Quoted 10 lines
testcases/commands/chrt/chrt01.sh new file +10 -0
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+# the GNU General Public License for more details.

The same here.

Quoted 16 lines
testcases/commands/chrt/chrt01.sh new file +16 -0
+#
+# Test the basic functionality of chrt command.
+#
+TST_TESTFUNC=chrt_test
+TST_SETUP=setup
+TST_CLEANUP=cleanup
+TST_NEEDS_CMDS="chrt cgexec cgset cgget"
+TST_NEEDS_ROOT=1
+. tst_test.sh
+
+setup()
+{
+	old_rt_runtime_us=$(cgget -r cpu.rt_runtime_us / -vn)
+	old_rt_period_us=$(cgget -r cpu.rt_period_us / -vn)
+
+	cgset -r cpu.rt_runtime_us=10000 /

testcases/commands/chrt/chrt01.sh line 39

Quoted 10 lines
testcases/commands/chrt/chrt01.sh new file +10 -0
+	cgset -r cpu.rt_period_us=1000000 /
+}
+
+chrt_test()
+{
+	cgexec -g cpu:/ -g cpuset:/ sleep 4 &
+	PID=$!
+	cgexec -g cpu:/ -g cpuset:/ chrt -arp 50 ${PID}
+	SCHEDULER=$(chrt -p ${PID} | awk 'NR==1{print $6}')
+	if [ x"${SCHEDULER}" == x"SCHED_RR" ]; then

Some basic rules for shell tests [2] are to check code on checkbashism.pl script or on /bin/sh linked as dash.
=> if [ "$scheduler" = "$sched_rr" ]; then

testcases/commands/chrt/chrt01.sh line 44

Quoted 5 lines
testcases/commands/chrt/chrt01.sh new file +5 -0
+		tst_res TPASS "'chrt' passed."
+	else
+		tst_res TFAIL "'chrt' failed to set scheduling policy."
+	fi
+}

Then, using local for local variables and lower case for local variables (preferably also for global variables, upper case are usually variables from shell libraries) =>
local pid
local scheduler

testcases/commands/chrt/chrt01.sh line 49

Quoted 5 lines
testcases/commands/chrt/chrt01.sh new file +5 -0
+
+cleanup()
+{
+	cgset -r cpu.rt_runtime_us=${old_rt_runtime_us} /
+	cgset -r cpu.rt_period_us=${old_rt_period_us} /

I get
cgset: wrong parameter of option -r: cpu.rt_runtime_us
cgset: wrong parameter of option -r: cpu.rt_period_us

Kind regards,
Petr

testcases/commands/chrt/chrt01.sh line 52

Quoted 3 lines
testcases/commands/chrt/chrt01.sh new file +3 -0
+}
+
+tst_run

[1] http://libcg.sourceforge.net/
[2] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#23-writing-a-testcase-in-shell