From 9a3324f50679177401eecdedcf80f25ddcdd9042 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 20 Nov 2024 15:30:44 +0000 Subject: usr: Add a strcmp example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- arch/riscv/usr/basics.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'arch/riscv/usr/basics.c') diff --git a/arch/riscv/usr/basics.c b/arch/riscv/usr/basics.c index 9b2267e..1d822c3 100644 --- a/arch/riscv/usr/basics.c +++ b/arch/riscv/usr/basics.c @@ -132,6 +132,25 @@ void test_atomic_add(void) printf("atomic_add:\t\tOK\n"); } +extern int mstrcmp(const char *s1, const char *s2); + +void test_mstrcmp(void) +{ + char *strings[] = { + "hello", "", "iello", "helloa", "contammusaaquellhomedegranarditquetantissimerra", + }; + + for (uint64_t i = 0; i < 1000000000; i++) { + assert(mstrcmp(strings[0], strings[0]) == 0); + assert(mstrcmp(strings[0], strings[1]) > 0); + assert(mstrcmp(strings[0], strings[2]) < 0); + assert(mstrcmp(strings[0], strings[3]) < 0); + assert(mstrcmp(strings[0], strings[4]) > 0); + } + + printf("mstrcmp:\t\tOK\n"); +} + int main() { test_factorial(); @@ -139,4 +158,5 @@ int main() test_is_palindrome(); test_greater_than_ten(); test_atomic_add(); + test_mstrcmp(); } -- cgit v1.2.3