Skip to content

Commit

Permalink
adaptived: ftests: let systemd create the test slice
Browse files Browse the repository at this point in the history
It is not necessary to create the test slice as systemd creates
the slice if it does not exist. Also, add runtime option so
that settings are temporary.

Signed-off-by: George Kennedy <[email protected]>
  • Loading branch information
gkennedy12 committed Nov 14, 2024
1 parent 240407d commit 296f832
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"setting": "MemoryMax",
"value": 89997312,
"operator": "set",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"target": "sudo1001.slice",
"setting": "MemoryMax",
"value": 89997312,
"operator": "set"
"operator": "set",
"runtime": true
}
},
{
Expand All @@ -26,7 +27,8 @@
"setting": "MemoryMax",
"value": 4096,
"operator": "add",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"target": "sudo1002.slice",
"setting": "MemoryMax",
"value": 89997312,
"operator": "set"
"operator": "set",
"runtime": true
}
},
{
Expand All @@ -26,7 +27,8 @@
"setting": "MemoryMax",
"value": 4096,
"operator": "subtract",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"target": "sudo1003.slice",
"setting": "CPUQuotaPeriodSec",
"value": "1s",
"operator": "set"
"operator": "set",
"runtime": true
}
},
{
Expand All @@ -25,7 +26,8 @@
"target": "sudo1003.slice",
"setting": "CPUQuota",
"value": "44%",
"operator": "set"
"operator": "set",
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"setting": "MemoryMax",
"value": "infinity",
"operator": "set",
"validate": true
"validate": true,
"runtime": true
}
},
{
Expand All @@ -27,7 +28,8 @@
"setting": "MemoryMax",
"value": 4096,
"operator": "add",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"setting": "MemoryMax",
"value": "infinity",
"operator": "set",
"validate": true
"validate": true,
"runtime": true
}
},
{
Expand All @@ -27,7 +28,8 @@
"setting": "MemoryMax",
"value": 4096,
"operator": "subtract",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"setting": "MemoryMax",
"value": 89997312,
"operator": "set",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ int main(int argc, char *argv[])
ret = adaptived_set_attr(ctx, ADAPTIVED_ATTR_LOG_LEVEL, LOG_DEBUG);
if (ret)
goto err;
ret = start_slice(cgroup_slice_name, "cat");
if (ret) {
adaptived_err("Failed to create slice: %s, ret=%d\n", cgroup_slice_name, ret);
goto err;
}

ret = adaptived_loop(ctx, true);
if (ret != EXPECTED_RET)
goto err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"setting": "DevicePolicy",
"value": "closed",
"operator": "set",
"validate": true
"validate": true,
"runtime": true
}
}
]
Expand Down
20 changes: 20 additions & 0 deletions adaptived/tests/ftests/ftests.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ double time_elapsed(const struct timespec * const start, const struct timespec *
int stop_transient(const char *transient_name)
{
char cmdline[FILENAME_MAX];
char *cgrp_path = NULL;
int ret;

if (!transient_name)
Expand All @@ -399,6 +400,25 @@ int stop_transient(const char *transient_name)
return ret;
ret = system(cmdline);
adaptived_dbg("stop_transient: %s, ret=%d\n", cmdline, ret);

ret = build_systemd_cgroup_path(transient_name, &cgrp_path);
if (ret < 0 || cgrp_path == NULL) {
adaptived_err("%s: Failed to build the systemd cgroup path for %s, ret: %d\n", __func__, transient_name, ret);
return ret;
}

if (access(cgrp_path, F_OK) == 0) {
adaptived_dbg("stop_transient: %s still exists...\n", cgrp_path);
ret = snprintf(cmdline, FILENAME_MAX - 1, "sudo rmdir %s", cgrp_path);
if (ret < 0)
return ret;
ret = system(cmdline);
adaptived_dbg("stop_transient: %s, ret=%d\n", cmdline, ret);
}

err:
if (cgrp_path)
free(cgrp_path);
return 0;
}

Expand Down

0 comments on commit 296f832

Please sign in to comment.