LCOV - code coverage report
Current view: top level - libc/test - run-memops.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 53 53 100.0 %
Date: 2024-01-02 21:04:04 Functions: 1 1 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :            : /*
       3                 :            :  * Copyright 2013-2015 IBM Corp.
       4                 :            :  */
       5                 :            : 
       6                 :            : #define BUFSZ 50
       7                 :            : 
       8                 :            : #include <stdlib.h>
       9                 :            : #include <assert.h>
      10                 :            : #include <string.h>
      11                 :            : #include <stdio.h>
      12                 :            : 
      13                 :            : int test_memset(char* buf, int c, size_t s);
      14                 :            : int test_memchr(const void *ptr, int c, size_t n, void* expected);
      15                 :            : int test_memcmp(const void *ptr1, const void *ptr2, size_t n, int expected);
      16                 :            : int test_strcmp(const void *ptr1, const void *ptr2, int expected);
      17                 :            : int test_strchr(const char *s, int c, char *expected);
      18                 :            : int test_strrchr(const char *s, int c, char *expected);
      19                 :            : int test_strcasecmp(const char *s1, const char *s2, int expected);
      20                 :            : int test_strncasecmp(const char *s1, const char *s2, size_t n, int expected);
      21                 :            : int test_memmove(void *dest, const void *src, size_t n, const void *r, const void *expected, size_t expected_n);
      22                 :            : 
      23                 :          5 : int main(void)
      24                 :            : {
      25                 :            :         char *buf;
      26                 :            :         char *buf2;
      27                 :            : 
      28                 :          5 :         buf = malloc(100);
      29                 :          5 :         assert(test_memset(buf, 0x42, 100) == 0);
      30                 :          5 :         free(buf);
      31                 :            : 
      32                 :          5 :         buf = malloc(128);
      33                 :          5 :         assert(test_memset(buf, 0, 128) == 0);
      34                 :          5 :         assert(test_memset(buf+1, 0, 127) == 0);
      35                 :          5 :         free(buf);
      36                 :            : 
      37                 :          5 :         buf = malloc(1024);
      38                 :          5 :         assert(test_memset(buf, 0, 1024) == 0);
      39                 :          5 :         free(buf);
      40                 :            : 
      41                 :          5 :         buf = malloc(20);
      42                 :          5 :         strncpy(buf, "Hello World!", 20);
      43                 :          5 :         assert(test_memchr(buf, 'o', strlen(buf), buf+4));
      44                 :          5 :         assert(test_memchr(buf, 'a', strlen(buf), NULL));
      45                 :            : 
      46                 :          5 :         assert(test_memcmp(buf, "Hello World!", strlen(buf), 0));
      47                 :          5 :         assert(test_memcmp(buf, "Hfllow World", strlen(buf), -1));
      48                 :            : 
      49                 :          5 :         assert(test_strcmp(buf, "Hello World!",  0));
      50                 :          5 :         assert(test_strcmp(buf, "Hfllow World", -1));
      51                 :            : 
      52                 :          5 :         assert(test_strchr(buf, 'H', buf));
      53                 :          5 :         assert(test_strchr(buf, 'e', buf+1));
      54                 :          5 :         assert(test_strchr(buf, 'a', NULL));
      55                 :          5 :         assert(test_strchr(buf, '!', buf+11));
      56                 :            : 
      57                 :          5 :         assert(test_strrchr(buf, 'H', buf));
      58                 :          5 :         assert(test_strrchr(buf, 'o', buf+7));
      59                 :          5 :         assert(test_strrchr(buf, 'a', NULL));
      60                 :          5 :         assert(test_strrchr(buf, 'l', buf+9));
      61                 :          5 :         assert(test_strrchr(buf, '!', buf+11));
      62                 :            : 
      63                 :          5 :         assert(test_strcasecmp(buf, "Hello World!", 0));
      64                 :          5 :         assert(test_strcasecmp(buf, "HELLO WORLD!", 0));
      65                 :          5 :         assert(test_strcasecmp(buf, "IELLO world!", -1));
      66                 :          5 :         assert(test_strcasecmp(buf, "HeLLo WOrlc!", 1));
      67                 :            : 
      68                 :          5 :         assert(test_strncasecmp(buf, "Hello World!", strlen(buf), 0));
      69                 :          5 :         assert(test_strncasecmp(buf, "HELLO WORLD!", strlen(buf), 0));
      70                 :          5 :         assert(test_strncasecmp(buf, "IELLO world!", strlen(buf), -1));
      71                 :          5 :         assert(test_strncasecmp(buf, "HeLLo WOrlc!", strlen(buf), 1));
      72                 :            : 
      73                 :          5 :         assert(test_strncasecmp(buf, "HeLLo WOrlc!", 0, 0));
      74                 :          5 :         assert(test_strncasecmp(buf, "HeLLo WOrlc!", 1, 0));
      75                 :          5 :         assert(test_strncasecmp(buf, "HeLLo WOrlc!", 2, 0));
      76                 :          5 :         assert(test_strncasecmp(buf, "HeLLp WOrlc!", 5, -1));
      77                 :            : 
      78                 :          5 :         free(buf);
      79                 :            : 
      80                 :          5 :         buf  = malloc(20);
      81                 :          5 :         buf2 = malloc(20);
      82                 :          5 :         strncpy(buf, "Hello", 20);
      83                 :          5 :         strncpy(buf2, " World!", 20);
      84                 :            : 
      85                 :          5 :         assert(test_memmove(buf + 5, buf2, strlen(buf2), buf,
      86                 :            :                             "Hello World!", strlen("Hello World!")));
      87                 :            : 
      88                 :          5 :         strncpy(buf, "HHello World!", 20);
      89                 :          5 :         assert(test_memmove(buf, buf+1, strlen("Hello World!"), buf, "Hello World!", strlen("Hello World!")));
      90                 :            : 
      91                 :          5 :         strncpy(buf, "0123456789", 20);
      92                 :          5 :         assert(test_memmove(buf+1, buf , strlen("0123456789"), buf, "00123456789", strlen("00123456789")));
      93                 :            : 
      94                 :          5 :         free(buf);
      95                 :          5 :         free(buf2);
      96                 :            : 
      97                 :          5 :         return 0;
      98                 :            : }

Generated by: LCOV version 1.14