]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
va_list struct is now properly closed
authorsstrehla <slawomir.strehlau@intel.com>
Sat, 18 Jul 2020 21:26:39 +0000 (23:26 +0200)
committersstrehla <slawomir.strehlau@intel.com>
Mon, 20 Jul 2020 08:54:50 +0000 (10:54 +0200)
fixed typos in smart_test.c
Replaced magic number of intel vid with define
Replaced magic string with const char* with better defined name
grammar fixes in smart.c

src/smart.c
src/smart_test.c

index c85bafa3c275a4c84225972708ff9f3ccdceddc1..e251d5286e74fc258efcdef07fecc77b852d1d77 100644 (file)
@@ -24,6 +24,7 @@
  *   Vincent Bernat <vbe at exoscale.ch>
  *   Maciej Fijalkowski <maciej.fijalkowski@intel.com>
  *   Bartlomiej Kotlowski <bartlomiej.kotlowski@intel.com>
+ *   Slawomir Strehlau <slawomir.strehlau@intel.com>
  **/
 
 #include "collectd.h"
@@ -234,8 +235,8 @@ static inline double int48_to_double(__u8 *data) {
 }
 
 /**
- * There is a bunch of metrics that are 16 bytes long and the need to be
- * converted onto the single double value, so they can be dispatched
+ * There is a bunch of metrics that are 16 bytes long and need to be
+ * converted into single double value, so they can be dispatched
  */
 #define NVME_METRIC_16B(metric)                                                \
   { "nvme_" #metric, offsetof(union nvme_smart_log, data.metric), "" }
index 4963b51ebcbda06a657c1d883c30238c309129b8..f458c851b1aeab9b54b61d93e48b6f3df4eb1dd4 100644 (file)
  *
  * Authors:
  *   Bartlomiej Kotlowski <bartlomiej.kotlowski@intel.com>
+ *   Slawomir Strehlau <slawomir.strehlau@intel.com>
  **/
 
 #include "smart.c"
 #include "testing.h"
 
-int VENDOR_ID = 0x8086;
-char *CORRECT_DEV_PATH = "/dev/nvme0n1";
+#define INTEL_VID 0x8086
+
+int VENDOR_ID = INTEL_VID;
+const char *CORRECT_DEV_PATH = "/dev/nvme0n1";
+const char *INCORRECT_DEV_PATH = "dev/nvme0nXX";
 
 int ioctl(int __fd, unsigned long int __request, ...) {
   va_list valist;
   va_start(valist, __request);
   struct nvme_admin_cmd *admin_cmd = va_arg(valist, struct nvme_admin_cmd *);
+  va_end(valist);
+  void *addr = (void *)admin_cmd->addr;
 
   if (admin_cmd->opcode == NVME_ADMIN_IDENTIFY) {
-    // icotl ask about vid
-    __le16 *vid = (__le16 *)admin_cmd->addr;
+    // ioctl asked about vid
+    __le16 *vid = (__le16 *)addr;
     *vid = VENDOR_ID;
     return 0;
   } else if (admin_cmd->opcode == NVME_ADMIN_GET_LOG_PAGE) {
-    // icotl ask about smart attributies
+    // ioctl asked about smart attributes
     if (admin_cmd->cdw10 == NVME_SMART_INTEL_CDW10) {
-      // set intel specyfic attrubiuties
+      // set intel specific attributes
       struct nvme_additional_smart_log *intel_smart_log =
-          (struct nvme_additional_smart_log *)admin_cmd->addr;
+          (struct nvme_additional_smart_log *)addr;
       intel_smart_log->program_fail_cnt.norm = 100;
       return 0;
     } else if (admin_cmd->cdw10 == NVME_SMART_CDW10) {
-      // set global smart attrubiuties
-      union nvme_smart_log *smart_log = (union nvme_smart_log *)admin_cmd->addr;
+      // set generic smart attributes
+      union nvme_smart_log *smart_log = (union nvme_smart_log *)addr;
       smart_log->data.critical_warning = 0;
       return 0;
     }
-    return -1; // no mock func
   }
-  return -1; // no mock func
+  return -1; // functionality not mocked
 };
 
 int open(const char *__path, int __oflag, ...) {
@@ -74,29 +79,24 @@ DEF_TEST(x) {
   ret = get_vendor_id(CORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(VENDOR_ID, ret);
 
-  VENDOR_ID = 0x144D;
+  VENDOR_ID = 0x0;
   ret = get_vendor_id(CORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(VENDOR_ID, ret);
-  VENDOR_ID = 0x8086;
+  VENDOR_ID = INTEL_VID;
 
-  // incorrect with DEV_PATH
-  ret = get_vendor_id("dev/nvme0nXX", "stub");
+  ret = get_vendor_id(INCORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(-1, ret);
 
   ret = smart_read_nvme_intel_disk(CORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(0, ret);
 
-  // incorrect with DEV_PATH
-  ret = smart_read_nvme_intel_disk("dev/nvme0nXX", "stub");
+  ret = smart_read_nvme_intel_disk(INCORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(-1, ret);
 
-  CORRECT_DEV_PATH = "dev/sda0";
-
   ret = smart_read_nvme_disk(CORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(0, ret);
 
-  // incorrect with DEV_PATH
-  ret = smart_read_nvme_disk("/dev/sdaXX", "stub");
+  ret = smart_read_nvme_disk(INCORRECT_DEV_PATH, "stub");
   EXPECT_EQ_INT(-1, ret);
 
   return 0;