[PATCH 3/3] edid-decode: Add test utility for libedid-decode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Shashank Sharma <shashank.sharma@xxxxxxx>

This patch adds a small test utility to show usage of
libedid-decode.

Cc: Pekka Paalanen <ppaalanen@xxxxxxxxx>
Cc: Jani Nikula <jani.nikula@xxxxxxxxx>

Signed-off-by: Shashank Sharma <contactshashanksharma@xxxxxxxxx>
---
 Makefile     |   3 ++
 test-lib.cpp | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)
 create mode 100644 test-lib.cpp

diff --git a/Makefile b/Makefile
index ebf3370..fdd02a0 100644
--- a/Makefile
+++ b/Makefile
@@ -44,6 +44,9 @@ edid-decode.js: $(SOURCES) edid-decode.h oui.h Makefile
 libedid-decode: $(SOURCES) edid-decode.h oui.h Makefile
 	$(CXX) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(WARN_FLAGS) -g $(LIB_FLAGS) $(sha) $(date) $(LIBLINK_FLAGS) -o $(LIB_NAME) $(LIB_SOURCES) $(SOURCES) -lm
 
+libedid-test:
+	$(CXX)  -o test-lib test-lib.cpp -g -L$(PWD) -ledid-decode
+
 clean:
 	rm -f edid-decode libedid-decode.so
 
diff --git a/test-lib.cpp b/test-lib.cpp
new file mode 100644
index 0000000..9b86adb
--- /dev/null
+++ b/test-lib.cpp
@@ -0,0 +1,121 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Author: Shashank Sharma <contactshashanksharma@xxxxxxxxx>
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include "libedid-decode-api.h"
+#define EDID_PATH "/sys/class/drm/card0-HDMI-A-1/edid"
+
+/* This is a sample program to demo the usages of libedid-decode */
+
+int main(void)
+{
+    int ret;
+    unsigned int u_ret;
+    struct edid_state *estate;
+    int w = 0, h = 0;
+
+    estate = libedid_parse_edid(EDID_PATH);
+    if (!estate) {
+        printf("Failed to parse EDID\n");
+        return -1;
+    }
+
+    printf("EDID parsing success\n");
+
+
+    ret = libedid_num_blks(estate);
+    if (ret < 0) {
+        printf("Error: failed to get num blocks\n");
+        return -1;
+    }
+    printf("EDID: No of blocks: %d\n", ret);
+
+    ret = libedid_has_cta_blks(estate);
+    if (ret < 0) {
+        printf("Error: failed to check CTA block\n");
+        return -1;
+    }
+    printf("EDID: EDID %s CTA blocks\n", ret ? "has" : "doesn't have");
+
+    ret = libedid_get_edid_version_minor(estate);
+    if (ret < 0) {
+        printf("Error: failed to check EDID version\n");
+        return -1;
+    }
+    printf("EDID: EDID version: 1.%d\n", ret);
+
+    ret = libedid_get_edid_get_num_dtd(estate);
+    if (ret < 0) {
+        printf("Error: failed to check EDID num DTDs\n");
+        return -1;
+    }
+    printf("EDID: EDID has %d DTDs\n", ret);
+
+    ret = libedid_if_preferred_mode_native(estate);
+    if (ret < 0) {
+        printf("Error: failed to check preferred mode\n");
+        return -1;
+    }
+    printf("EDID: EDID preferred mode is %s\n", ret ? "native" : "not native");
+
+    ret = libedid_get_max_display_w_h_mm(estate, &w, &h);
+    if (ret < 0) {
+        printf("Error: failed to check height/width\n");
+        return -1;
+    }
+    printf("EDID: EDID hxw is %dx%d\n", w, h);
+
+    ret = libedid_ctablk_has_hdmi(estate);
+    if (ret < 0) {
+        printf("Error: failed to check CTA HDMI support\n");
+        return -1;
+    }
+    printf("EDID: CTA block %s HDMI\n", ret ? "supports" : "doesn't support");
+
+    ret = libedid_ctablk_has_vcdb(estate);
+    if (ret < 0) {
+        printf("Error: failed to check CTA VCDB support\n");
+        return -1;
+    }
+    printf("EDID: CTA block %s VCDB\n", ret ? "has" : "doesn't have");
+
+    ret = libedid_ctablk_has_hfvsdb(estate);
+    if (ret < 0) {
+        printf("Error: failed to check CTA HF-VSDB support\n");
+        return -1;
+    }
+    printf("EDID: CTA block %s HF-VSDB\n", ret ? "has" : "doesn't have");
+
+    u_ret = libedid_get_max_pclk_khz(estate);
+    if (u_ret == 0) {
+        printf("Error: failed to get max pixel clock\n");
+        return -1;
+    }
+    printf("EDID: EDID's max pixel clock is %u KHz\n", u_ret);
+
+    u_ret = libedid_get_max_hfreq_hz(estate);
+    if (u_ret == 0) {
+        printf("Error: failed to get max hfreq\n");
+        return -1;
+    }
+    printf("EDID: EDID's max hfreq is %u Hz\n", u_ret);
+
+    u_ret = libedid_get_max_vfreq_hz(estate);
+    if (u_ret == 0) {
+        printf("Error: failed to get max vfreq\n");
+        return -1;
+    }
+    printf("EDID: EDID's max vfreq is %u Hz\n", u_ret);
+
+    u_ret = libedid_ctablk_supported_hdmi_vics(estate);
+    if (u_ret == 0) {
+        printf("Error: failed to get supported VICs\n");
+        return -1;
+    }
+    printf("EDID: EDID's supported HDMI VICs map is %u\n", u_ret);
+
+    return 0;
+}
\ No newline at end of file
-- 
2.32.0




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux