LCOV - code coverage report
Current view: top level - libstb/secvar/test - secvar-test-enqueue.c (source / functions) Coverage Total Hit
Test: skiboot.info Lines: 100.0 % 68 68
Test Date: 2025-01-24 18:40:10 Functions: 100.0 % 2 2
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :             : /* Copyright 2019 IBM Corp. */
       3                 :             : 
       4                 :             : #include "secvar_api_test.c"
       5                 :             : 
       6                 :             : const char *secvar_test_name = "enqueue";
       7                 :             : 
       8                 :             : // Stub storage function, enqueue only cares that this succeeds
       9                 :           5 : static int temp_write_bank(struct list_head *bank, int section)
      10                 :             : {
      11                 :             :         (void) bank, (void) section;
      12                 :           5 :         return OPAL_SUCCESS;
      13                 :             : }
      14                 :             : 
      15                 :           1 : int run_test(void)
      16                 :             : {
      17                 :             :         int64_t rc;
      18                 :             : 
      19                 :             :         struct secvar *var;
      20                 :           1 :         char key[1024] = {0};
      21                 :             : 
      22                 :           1 :         uint64_t data_size = 128;
      23                 :           1 :         char *data = zalloc(data_size);
      24                 :             : 
      25                 :           1 :         secvar_storage.max_var_size = 1024;
      26                 :             : 
      27                 :             :         /*** Bad cases first this time ***/
      28                 :             :         // No write bank hook set
      29                 :           1 :         secvar_storage.write_bank = NULL;
      30                 :           1 :         memcpy(key, "meow", 4); // ascii
      31                 :           1 :         rc = secvar_enqueue(key, 4, data, data_size);
      32                 :           1 :         ASSERT(rc == OPAL_HARDWARE);
      33                 :             : 
      34                 :             :         // Set a stub bank writer, so the rest runs ok
      35                 :           1 :         secvar_storage.write_bank = temp_write_bank;
      36                 :             : 
      37                 :             :         // Parameter checks
      38                 :             :         // null key
      39                 :           1 :         rc = secvar_enqueue(NULL, 5, data, data_size);
      40                 :           1 :         ASSERT(rc == OPAL_PARAMETER);
      41                 :           1 :         ASSERT(list_empty(&update_bank));
      42                 :             : 
      43                 :             :         // key is empty
      44                 :           1 :         memset(key, 0, sizeof(key));
      45                 :           1 :         rc = secvar_enqueue(key, 5, data, data_size);
      46                 :           1 :         ASSERT(rc == OPAL_PARAMETER);
      47                 :           1 :         ASSERT(list_empty(&update_bank));
      48                 :             : 
      49                 :             :         // keylen is zero
      50                 :           1 :         rc = secvar_enqueue(key, 0, data, data_size);
      51                 :           1 :         ASSERT(rc == OPAL_PARAMETER);
      52                 :           1 :         ASSERT(list_empty(&update_bank));
      53                 :             : 
      54                 :             :         // keylen is excessive
      55                 :           1 :         rc = secvar_enqueue(key, 5000, data, data_size);
      56                 :           1 :         ASSERT(rc == OPAL_PARAMETER);
      57                 :           1 :         ASSERT(list_empty(&update_bank));
      58                 :             : 
      59                 :             :         // null data
      60                 :           1 :         rc = secvar_enqueue(key, 5, NULL, data_size);
      61                 :           1 :         ASSERT(rc == OPAL_PARAMETER);
      62                 :           1 :         ASSERT(list_empty(&update_bank));
      63                 :             : 
      64                 :             :         // data_size is excessive
      65                 :           1 :         rc = secvar_enqueue(key, 5, data, 50000);
      66                 :           1 :         ASSERT(rc == OPAL_PARAMETER);
      67                 :           1 :         ASSERT(list_empty(&update_bank));
      68                 :             : 
      69                 :             :         // data_size is zero
      70                 :           1 :         rc = secvar_enqueue(key, 5, data, 0);
      71                 :           1 :         ASSERT(rc == OPAL_PARAMETER);
      72                 :           1 :         ASSERT(list_empty(&update_bank));
      73                 :             : 
      74                 :             :         // secvar is disabled
      75                 :           1 :         secvar_enabled = 0;
      76                 :           1 :         rc = secvar_enqueue(key, 5, data, data_size);
      77                 :           1 :         ASSERT(rc == OPAL_UNSUPPORTED);
      78                 :           1 :         secvar_enabled = 1;
      79                 :             : 
      80                 :             :         // secvar is not ready
      81                 :           1 :         secvar_ready = 0;
      82                 :           1 :         rc = secvar_enqueue(key, 5, data, data_size);
      83                 :           1 :         ASSERT(rc == OPAL_RESOURCE);
      84                 :           1 :         secvar_ready = 1;
      85                 :             : 
      86                 :             : 
      87                 :             :         /*** Good cases ***/
      88                 :             :         // TODO: add data?
      89                 :           1 :         memcpy(key, "test", 4); // ascii
      90                 :           1 :         rc = secvar_enqueue(key, 4, data, data_size);
      91                 :           1 :         ASSERT(rc == OPAL_SUCCESS);
      92                 :           1 :         ASSERT(list_length(&update_bank) == 1);
      93                 :             : 
      94                 :           1 :         memcpy(key, "f\0o\0o\0b\0a\0r\0", 6*2); // "unicode"
      95                 :           1 :         rc = secvar_enqueue(key, 6*2, data, data_size);
      96                 :           1 :         ASSERT(rc == OPAL_SUCCESS);
      97                 :           1 :         ASSERT(list_length(&update_bank) == 2);
      98                 :             : 
      99                 :           1 :         memcpy(key, "meep", 4);
     100                 :           1 :         rc = secvar_enqueue(key, 4, data, data_size);
     101                 :           1 :         ASSERT(rc == OPAL_SUCCESS);
     102                 :           1 :         ASSERT(list_length(&update_bank) == 3); // should not increase
     103                 :             : 
     104                 :             :         // Re-add the same variable
     105                 :           1 :         memcpy(key, "meep", 4);
     106                 :           1 :         rc = secvar_enqueue(key, 4, data, data_size);
     107                 :           1 :         ASSERT(rc == OPAL_SUCCESS);
     108                 :           1 :         ASSERT(list_length(&update_bank) == 3); // should not increase
     109                 :           1 :         var = list_tail(&update_bank, struct secvar, link);
     110                 :           1 :         ASSERT(!memcmp(var->key, key, 4))    // should be at end
     111                 :             : 
     112                 :             :         // Unstage the variable update
     113                 :           1 :         rc = secvar_enqueue(key, 4, NULL, 0);
     114                 :           1 :         ASSERT(rc == OPAL_SUCCESS);
     115                 :           1 :         ASSERT(list_length(&update_bank) == 2);
     116                 :             : 
     117                 :             :         // Unstage a bogus variable update
     118                 :           1 :         rc = secvar_enqueue("nada", 4, NULL, 0);
     119                 :           1 :         ASSERT(rc == OPAL_EMPTY);
     120                 :           1 :         ASSERT(list_length(&update_bank) == 2);
     121                 :             : 
     122                 :             : 
     123                 :             :         // Empty the in-memory cache, and reload from "pnor"
     124                 :             :         //   Removed to drop dependency on a storage backend
     125                 :             :         //   Probably not actually necessary to test, that's the
     126                 :             :         //   job of the storage backend tests
     127                 :             :         /*
     128                 :             :         clear_bank_list(&update_bank);
     129                 :             :         ASSERT(list_empty(&update_bank));
     130                 :             :         secvar_storage.load_bank(&update_bank, SECVAR_UPDATE_BANK);
     131                 :             :         printf("list_length = %d\n", list_length(&update_bank));
     132                 :             :         ASSERT(list_length(&update_bank) == 2);
     133                 :             : 
     134                 :             :         node = list_top(&update_bank, struct secvar_node, link);
     135                 :             :         ASSERT(node);
     136                 :             :         ASSERT(!memcmp(node->var->key, "test", 4));
     137                 :             :         node = list_next(&update_bank, node, link);
     138                 :             :         ASSERT(node);
     139                 :             :         ASSERT(!memcmp(node->var->key, "f\0o\0o\0b\0a\0r\0", 6*2));
     140                 :             :         */
     141                 :             : 
     142                 :             :         /*** ONE more bad case... ***/
     143                 :             : 
     144                 :           1 :         free(data);
     145                 :             : 
     146                 :           1 :         return 0;
     147                 :             : 
     148                 :             : }
        

Generated by: LCOV version 2.0-1