commit: 90770e9741b3b2ceb69056905c310bf236f04da5
parent ff8d57f736593352ba96f2b4539916addf14732c
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 23 Sep 2025 12:49:07 +0200
Toss out ATF & Kyua
* Less code overall
* Allows static-linking
* Much better test output, specially in case of failure
Diffstat:
3 files changed, 63 insertions(+), 37 deletions(-)
diff --git a/Makefile b/Makefile
@@ -32,11 +32,11 @@ su: $(su_SRC) Makefile
$(CC) -std=c11 $(CFLAGS) -o $@ $(su_SRC) -lcrypt $(LDFLAGS) $(LDSTATIC)
common_test: common_test.c common.c Makefile
- $(CC) -std=c11 $(CFLAGS) `pkg-config --cflags atf-c` -o $@ common_test.c common.c `pkg-config --libs atf-c` -lcrypt $(LDFLAGS)
+ $(CC) -std=c11 $(CFLAGS) -o $@ common_test.c common.c -lcrypt $(LDFLAGS) $(LDSTATIC)
-.PHONY: test
-test: $(TEST_EXE)
- kyua test || (kyua report --verbose; false)
+.PHONY: check
+check: $(TEST_EXE)
+ ./common_test
.PHONY: install
install: all
diff --git a/README.md b/README.md
@@ -12,8 +12,6 @@ Status: Experimental, enough done to work but needs thorough review.
- C11 Compiler
- Proper support for static executables (glibc is out)
- `initgroups()` C interface in `<grp.h>` or `<unistd.h>`
-- (test-only) [ATF](https://github.com/jmmv/atf)
-- (test-only) [Kyua](https://github.com/jmmv/kyua)
- (lint-only) [mandoc](https://mdocml.bsd.lv/)
## Unsupported
diff --git a/common_test.c b/common_test.c
@@ -2,55 +2,83 @@
// SPDX-License-Identifier: MPL-2.0
#include "common.h"
+#include <stdio.h>
-#include <atf-c.h> // ATF*, atf*
+int counter = 0;
+int err = 0;
-ATF_TC(hash_match_tc);
-ATF_TC_HEAD(hash_match_tc, tc)
+static void
+test_hash_match(int ret, const char *s1, const char *s2)
{
- atf_tc_set_md_var(tc, "descr", "hash_match returns correct values");
-}
-ATF_TC_BODY(hash_match_tc, tc)
-{
- // Maybe check for constant time somehow?
- ATF_CHECK(hash_match("foo", "foo"));
- ATF_CHECK(!hash_match("foo", "bar"));
- ATF_CHECK(!hash_match("foo", "fooo"));
- ATF_CHECK(!hash_match("fooo", "foo"));
+ int id = ++counter;
+ int got = hash_match(s1, s2);
+
+ if(got == ret)
+ {
+ printf("ok %d - hash_match(\"%s\", \"%s\") == %d\n", id, s1, s2, ret);
+ return;
+ }
+
+ err = 1;
+
+ printf("not ok %d - hash_match(\"%s\", \"%s\") == %d\n", id, s1, s2, ret);
+ printf("# Got: %d\n", got);
}
-ATF_TC(skeud_crypt_check_tc);
-ATF_TC_HEAD(skeud_crypt_check_tc, tc)
+static void
+test_crypt_check(int ret, const char *s1, const char *s2)
{
- atf_tc_set_md_var(tc, "descr", "skeud_crypt_check returns correct values");
+ int id = ++counter;
+ int got = skeud_crypt_check(s1, s2);
+
+ if(got == ret)
+ {
+ printf("ok %d - skeud_crypt_check(\"%s\", \"%s\") == %d\n", id, s1, s2, ret);
+ return;
+ }
+
+ err = 1;
+
+ printf("not ok %d - skeud_crypt_check(\"%s\", \"%s\") == %d\n", id, s1, s2, ret);
+ printf("# Got: %d\n", got);
}
-ATF_TC_BODY(skeud_crypt_check_tc, tc)
+
+int
+main(void)
{
- ATF_CHECK(!skeud_crypt_check(NULL, "foobar"));
- ATF_CHECK(!skeud_crypt_check("", "foobar"));
- ATF_CHECK(!skeud_crypt_check("x", "foobar"));
- ATF_CHECK(!skeud_crypt_check("foobar", "foobar"));
+ int plan = 12;
+ printf("1..%d\n", plan);
+
+ test_hash_match(1, "foo", "foo");
+ test_hash_match(0, "foo", "bar");
+ test_hash_match(0, "foo", "fooo");
+ test_hash_match(0, "fooo", "foo");
+
+ test_crypt_check(0, NULL, "foobar");
+ test_crypt_check(0, "", "foobar");
+ test_crypt_check(0, "x", "foobar");
+ test_crypt_check(0, "foobar", "foobar");
// DES: openssl passwd -noverify
- ATF_CHECK(skeud_crypt_check("FmuFhHU.nJlkg", "foobar"));
+ test_crypt_check(1, "FmuFhHU.nJlkg", "foobar");
// MD5: openssl passwd -1 -noverify
- ATF_CHECK(skeud_crypt_check("$1$L0.ptviH$oU/aJvI7BwUtWXzeJ3nGU.", "foobar"));
+ test_crypt_check(1, "$1$L0.ptviH$oU/aJvI7BwUtWXzeJ3nGU.", "foobar");
// SHA256: openssl passwd -5 -noverify
- ATF_CHECK(skeud_crypt_check("$5$8VryLuwDTzZ8MSZX$2UIaWB5LcMlhXv7UQIBcFeq8/Dr6PswXZP/SJ09L01B",
- "foobar"));
+ test_crypt_check(1, "$5$8VryLuwDTzZ8MSZX$2UIaWB5LcMlhXv7UQIBcFeq8/Dr6PswXZP/SJ09L01B", "foobar");
+
// SHA512: openssl passwd -6 -noverify
const char *hash =
"$6$QUEEGuX9dkGlNkTP$IJwcvb6tpm63hoOfm9QJjEgjte/OpcQS3S43zDN95G3diJ5Xc/OlhhbCkUyV/"
"A0ARhgQj2D/4m/DWhwvvs3A91";
- ATF_CHECK(skeud_crypt_check(hash, "foobar"));
-}
+ test_crypt_check(1, hash, "foobar");
-ATF_TP_ADD_TCS(tp)
-{
- ATF_TP_ADD_TC(tp, hash_match_tc);
- ATF_TP_ADD_TC(tp, skeud_crypt_check_tc);
+ if(counter != plan)
+ {
+ fprintf(stderr, "common_test: error: Ran %d tests, expected %d\n", counter, plan);
+ return 1;
+ }
- return atf_no_error();
+ return err;
}