[2/2] tests: test that multi-line cgroup devices are restored correctly

Submitted by Tycho Andersen on July 1, 2016, 5:23 p.m.

Details

Message ID 1467393824-16778-2-git-send-email-tycho.andersen@canonical.com
State Accepted
Series "Series without cover letter"
Commit 1a95e42d76c252fea9a0dadd52a9e457cb9ff3be
Headers show

Commit Message

Tycho Andersen July 1, 2016, 5:23 p.m.
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
---
 test/zdtm/static/cgroup04.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/cgroup04.c b/test/zdtm/static/cgroup04.c
index a9746ae..65d9c31 100644
--- a/test/zdtm/static/cgroup04.c
+++ b/test/zdtm/static/cgroup04.c
@@ -79,17 +79,22 @@  err_rd:
 
 bool checkval(char *path, char *val)
 {
-	FILE *f;
 	char buf[64];
+	int fd, n;
 
-	f = fopen(path, "r");
-	if (!f) {
-		pr_perror("fopen %s", path);
+	fd = open(path, O_RDONLY);
+	if (fd < 0) {
+		pr_perror("open %s", path);
 		return false;
 	}
 
-	fgets(buf, sizeof(buf), f);
-	fclose(f);
+	n = read(fd, buf, sizeof(buf));
+	close(fd);
+	if (n < 0) {
+		pr_perror("read");
+		return false;
+	}
+	buf[n] = 0;
 
 	if (strcmp(val, buf)) {
 		pr_err("got %s expected %s\n", buf, val);
@@ -114,6 +119,9 @@  int main(int argc, char **argv)
 	if (write_value(path, "c 1:3 rwm") < 0)
 		goto out;
 
+	if (write_value(path, "c 1:5 rwm") < 0)
+		goto out;
+
 	if (mount_and_add("memory", cgname, "memory.limit_in_bytes", "268435456") < 0)
 		goto out;
 
@@ -121,7 +129,7 @@  int main(int argc, char **argv)
 	test_waitsig();
 
 	sprintf(path, "%s/devices/%s/devices.list", dirname, cgname);
-	if (!checkval(path, "c 1:3 rwm\n")) {
+	if (!checkval(path, "c 1:3 rwm\nc 1:5 rwm\n")) {
 		fail();
 		goto out;
 	}