condition: add CPUFeature

Taking a stab at implementing #14479.

Add {Condition,Assert}CPUFeature to `systemd-analyze` & friends. Implement it
by executing the CPUID instruction. Add tables for common x86/i386
features.

Tested via unit tests + checked that commands such as:

```bash
systemd-analyze condition 'AssertCPUFeature = rdrand'
```

Succeed as expected and that commands such as

```bash
systemd-analyze condition 'AssertCPUFeature = foobar'
```

Fail as expected. Finally, I have amended the `systemd.unit` manual page
with the new condition and the list of all currently supported flags.
This commit is contained in:
Giedrius Statkevičius
2021-02-17 15:31:29 +09:00
committed by Yu Watanabe
parent b1b4e9204c
commit 68337e55f6
6 changed files with 224 additions and 0 deletions
+24
View File
@@ -439,6 +439,27 @@ static void test_condition_test_kernel_version(void) {
condition_free(condition);
}
#if defined(__i386__) || defined(__x86_64__)
static void test_condition_test_cpufeature(void) {
Condition *condition;
condition = condition_new(CONDITION_CPU_FEATURE, "fpu", false, false);
assert_se(condition);
assert_se(condition_test(condition, environ) > 0);
condition_free(condition);
condition = condition_new(CONDITION_CPU_FEATURE, "somecpufeaturethatreallydoesntmakesense", false, false);
assert_se(condition);
assert_se(condition_test(condition, environ) == 0);
condition_free(condition);
condition = condition_new(CONDITION_CPU_FEATURE, "a", false, false);
assert_se(condition);
assert_se(condition_test(condition, environ) == 0);
condition_free(condition);
}
#endif
static void test_condition_test_security(void) {
Condition *condition;
@@ -864,6 +885,9 @@ int main(int argc, char *argv[]) {
test_condition_test_cpus();
test_condition_test_memory();
test_condition_test_environment();
#if defined(__i386__) || defined(__x86_64__)
test_condition_test_cpufeature();
#endif
return 0;
}