[v2,1/4] test: ipa: Add basic Pwl test
diff mbox series

Message ID 20250613100947.589875-2-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • ipa: pwl: Fixes for single point PWLs
Related show

Commit Message

Stefan Klug June 13, 2025, 10:09 a.m. UTC
Add a basic test for the Pwl class.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

---
Changes in v2:
- Changed test to also test extrapolation
---
 test/ipa/libipa/meson.build |  1 +
 test/ipa/libipa/pwl.cpp     | 50 +++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
 create mode 100644 test/ipa/libipa/pwl.cpp

Patch
diff mbox series

diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build
index 8c63ebd8e2f7..b2cc4b7461c1 100644
--- a/test/ipa/libipa/meson.build
+++ b/test/ipa/libipa/meson.build
@@ -4,6 +4,7 @@  libipa_test = [
     {'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']},
     {'name': 'histogram', 'sources': ['histogram.cpp']},
     {'name': 'interpolator', 'sources': ['interpolator.cpp']},
+    {'name': 'pwl', 'sources': ['pwl.cpp']},
 ]
 
 foreach test : libipa_test
diff --git a/test/ipa/libipa/pwl.cpp b/test/ipa/libipa/pwl.cpp
new file mode 100644
index 000000000000..d41a290a0e84
--- /dev/null
+++ b/test/ipa/libipa/pwl.cpp
@@ -0,0 +1,50 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2025, Ideas on Board Oy
+ *
+ * PWL tests
+ */
+
+#include "../src/ipa/libipa/pwl.h"
+
+#include <cmath>
+#include <iostream>
+#include <map>
+#include <stdint.h>
+#include <stdio.h>
+
+#include "test.h"
+
+using namespace std;
+using namespace libcamera;
+using namespace ipa;
+
+#define ASSERT_EQ(a, b)                                                 \
+	if ((a) != (b)) {                                               \
+		std::cout << #a " != " #b " (" << a << " ," << b << ")" \
+			  << std::endl;                                 \
+		return TestFail;                                        \
+	}
+
+class PwlTest : public Test
+{
+protected:
+	int run()
+	{
+		Pwl pwl;
+		pwl.append(0, 0);
+		pwl.append(1, 1);
+
+		ASSERT_EQ(pwl.eval(-1), -1);
+		ASSERT_EQ(pwl.eval(0), 0);
+		ASSERT_EQ(pwl.eval(0.5), 0.5);
+		ASSERT_EQ(pwl.eval(1), 1);
+		ASSERT_EQ(pwl.eval(2), 2);
+
+		ASSERT_EQ(pwl.size(), 2);
+
+		return TestPass;
+	}
+};
+
+TEST_REGISTER(PwlTest)