LCOV - code coverage report
Current view: top level - libc/test - run-memops-test.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 23 25 92.0 %
Date: 2024-01-02 21:04:04 Functions: 9 9 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                 :            :  * This file is run with the skiboot libc files rather than system libc.
       6                 :            :  * This means we have a bit of "fun" with actually executing the tests on
       7                 :            :  * the host.
       8                 :            :  * Patches to make this less ugly are very welcome.
       9                 :            :  */
      10                 :            : 
      11                 :            : #include <config.h>
      12                 :            : #include <stdarg.h>
      13                 :            : 
      14                 :            : #include "../string/memchr.c"
      15                 :            : #include "../string/memcmp.c"
      16                 :            : #include "../string/memcpy.c"
      17                 :            : #include "../string/memmove.c"
      18                 :            : #include "../string/memset.c"
      19                 :            : #include "../string/strcasecmp.c"
      20                 :            : #include "../string/strcat.c"
      21                 :            : #include "../string/strchr.c"
      22                 :            : #include "../string/strrchr.c"
      23                 :            : #include "../string/strcmp.c"
      24                 :            : #include "../string/strcpy.c"
      25                 :            : /* #include "../string/strdup.c" */
      26                 :            : #include "../string/strlen.c"
      27                 :            : #include "../string/strncasecmp.c"
      28                 :            : #include "../string/strncmp.c"
      29                 :            : #include "../string/strncpy.c"
      30                 :            : #include "../string/strstr.c"
      31                 :            : #include "../string/strtok.c"
      32                 :            : #include <stdlib.h>
      33                 :            : 
      34                 :            : int test_memset(char* buf, int c, size_t s);
      35                 :            : int test_memchr(const void *ptr, int c, size_t n, void* expected);
      36                 :            : int test_memcmp(const void *ptr1, const void *ptr2, size_t n, int expected);
      37                 :            : int test_strcmp(const void *ptr1, const void *ptr2, int expected);
      38                 :            : int test_strchr(const char *s, int c, char *expected);
      39                 :            : int test_strrchr(const char *s, int c, char *expected);
      40                 :            : int test_strcasecmp(const char *s1, const char *s2, int expected);
      41                 :            : int test_strncasecmp(const char *s1, const char *s2, size_t n, int expected);
      42                 :            : int test_memmove(void *dest, const void *src, size_t n, const void *r, const void *expected, size_t expected_n);
      43                 :            : 
      44                 :         20 : int test_memset(char* buf, int c, size_t s)
      45                 :            : {
      46                 :            :         int i;
      47                 :         20 :         int r= 0;
      48                 :            : 
      49                 :         20 :         memset(buf, c, s);
      50                 :       6915 :         for(i=0; i<s; i++)
      51                 :       6895 :                 if (buf[i] != c)
      52                 :          0 :                         r = -1;
      53                 :            : 
      54                 :         20 :         return r;
      55                 :            : }
      56                 :            : 
      57                 :         10 : int test_memchr(const void *ptr, int c, size_t n, void* expected)
      58                 :            : {
      59                 :         10 :         return(expected == memchr(ptr, c, n));
      60                 :            : }
      61                 :            : 
      62                 :         10 : int test_memcmp(const void *ptr1, const void *ptr2, size_t n, int expected)
      63                 :            : {
      64                 :         10 :         return(expected == memcmp(ptr1, ptr2, n));
      65                 :            : }
      66                 :            : 
      67                 :         10 : int test_strcmp(const void *ptr1, const void *ptr2, int expected)
      68                 :            : {
      69                 :         10 :         return(expected == strcmp(ptr1, ptr2));
      70                 :            : }
      71                 :            : 
      72                 :         20 : int test_strchr(const char *s, int c, char *expected)
      73                 :            : {
      74                 :         20 :         return(expected == strchr(s, c));
      75                 :            : }
      76                 :            : 
      77                 :         25 : int test_strrchr(const char *s, int c, char *expected)
      78                 :            : {
      79                 :         25 :         return(expected == strrchr(s, c));
      80                 :            : }
      81                 :            : 
      82                 :         20 : int test_strcasecmp(const char *s1, const char *s2, int expected)
      83                 :            : {
      84                 :         20 :         return(expected == strcasecmp(s1, s2));
      85                 :            : }
      86                 :            : 
      87                 :         40 : int test_strncasecmp(const char *s1, const char *s2, size_t n, int expected)
      88                 :            : {
      89                 :         40 :         return(expected == strncasecmp(s1, s2, n));
      90                 :            : }
      91                 :            : 
      92                 :         15 : int test_memmove(void *dest, const void *src, size_t n, const void *r, const void *expected, size_t expected_n)
      93                 :            : {
      94                 :         15 :         if (memmove(dest, src, n) != dest)
      95                 :          0 :                 return -1;
      96                 :         15 :         return(memcmp(r, expected, expected_n) == 0);
      97                 :            : }

Generated by: LCOV version 1.14