[PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation

Frank Oltmanns posted 2 patches 2 years, 7 months ago
There is a newer version of this series
[PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation
Posted by Frank Oltmanns 2 years, 7 months ago
In light of the recent discovery that the fractional divisor
approximation does not utilize the full available range for clocks that
are flagged CLK_FRAC_DIVIDER_ZERO_BASED, implement tests for the edge
cases of this clock type.

Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
Link: https://lore.kernel.org/lkml/20230529133433.56215-1-frank@oltmanns.dev
---
 drivers/clk/clk_test.c | 69 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 68 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index f9a5c2964c65..b247ba841cbd 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -8,6 +8,9 @@
 /* Needed for clk_hw_get_clk() */
 #include "clk.h"
 
+/* Needed for clk_fractional_divider_general_approximation */
+#include "clk-fractional-divider.h"
+
 #include <kunit/test.h>
 
 #define DUMMY_CLOCK_INIT_RATE	(42 * 1000 * 1000)
@@ -2394,6 +2397,69 @@ static struct kunit_suite clk_mux_notifier_test_suite = {
 	.test_cases = clk_mux_notifier_test_cases,
 };
 
+
+/*
+ * Test that clk_fractional_divider_general_approximation will work with the
+ * highest available numerator and denominator.
+ */
+static void clk_fd_test_round_rate_max_mn(struct kunit *test)
+{
+	struct clk_fractional_divider *fd;
+	struct clk_hw *hw;
+	unsigned long rate, parent_rate, m, n;
+
+	fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, fd);
+
+	fd->mwidth = 3;
+	fd->nwidth = 3;
+
+	hw = &fd->hw;
+
+	rate = DUMMY_CLOCK_RATE_1;
+
+	// Highest denominator, no flags
+	parent_rate = 10 * DUMMY_CLOCK_RATE_1;
+	clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
+	KUNIT_EXPECT_EQ(test, m, 1);
+	KUNIT_EXPECT_EQ(test, n, 7);
+
+	// Highest numerator, no flags
+	parent_rate = DUMMY_CLOCK_RATE_1 / 10;
+	clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
+	KUNIT_EXPECT_EQ(test, m, 7);
+	KUNIT_EXPECT_EQ(test, n, 1);
+
+	// Highest denominator, zero based
+	parent_rate = 10 * DUMMY_CLOCK_RATE_1;
+	fd->flags = CLK_FRAC_DIVIDER_ZERO_BASED;
+	clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
+	KUNIT_EXPECT_EQ(test, m, 1);
+	KUNIT_EXPECT_EQ(test, n, 8);
+
+	// Highest numerator, zero based
+	parent_rate = DUMMY_CLOCK_RATE_1 / 10;
+	clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
+	KUNIT_EXPECT_EQ(test, m, 8);
+	KUNIT_EXPECT_EQ(test, n, 1);
+}
+
+static struct kunit_case clk_fd_test_cases[] = {
+	KUNIT_CASE(clk_fd_test_round_rate_max_mn),
+	{}
+};
+
+/*
+ * Test suite for a fractional divider clock.
+ *
+ * These tests exercise the fractional divider API: clk_recalc_rate,
+ * clk_set_rate(), clk_round_rate().
+ */
+static struct kunit_suite clk_fd_test_suite = {
+	.name = "clk-fd-test",
+	.test_cases = clk_fd_test_cases,
+};
+
 kunit_test_suites(
 	&clk_leaf_mux_set_rate_parent_test_suite,
 	&clk_test_suite,
@@ -2406,6 +2472,7 @@ kunit_test_suites(
 	&clk_range_maximize_test_suite,
 	&clk_range_minimize_test_suite,
 	&clk_single_parent_mux_test_suite,
-	&clk_uncached_test_suite
+	&clk_uncached_test_suite,
+	&clk_fd_test_suite
 );
 MODULE_LICENSE("GPL v2");
-- 
2.41.0
Re: [PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation
Posted by kernel test robot 2 years, 7 months ago
Hi Frank,

kernel test robot noticed the following build errors:

[auto build test ERROR on v6.4-rc6]
[also build test ERROR on linus/master]
[cannot apply to clk/clk-next next-20230613]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Frank-Oltmanns/clk-fractional-divider-Improve-approximation-when-zero-based/20230613-163903
base:   v6.4-rc6
patch link:    https://lore.kernel.org/r/20230613083626.227476-3-frank%40oltmanns.dev
patch subject: [PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation
config: csky-randconfig-r011-20230612 (https://download.01.org/0day-ci/archive/20230613/202306132038.nUB6hmCv-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 12.3.0
reproduce (this is a W=1 build):
        mkdir -p ~/bin
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        git checkout v6.4-rc6
        b4 shazam https://lore.kernel.org/r/20230613083626.227476-3-frank@oltmanns.dev
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=csky olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=csky SHELL=/bin/bash

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306132038.nUB6hmCv-lkp@intel.com/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "clk_fractional_divider_general_approximation" [drivers/clk/clk_test.ko] undefined!

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation
Posted by Frank Oltmanns 2 years, 7 months ago
Hi,

On 2023-06-13 at 20:48:21 +0800, kernel test robot <lkp@intel.com> wrote:
> Hi Frank,
>
> kernel test robot noticed the following build errors:
>
> [auto build test ERROR on v6.4-rc6]
> [also build test ERROR on linus/master]
> [cannot apply to clk/clk-next next-20230613]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Frank-Oltmanns/clk-fractional-divider-Improve-approximation-when-zero-based/20230613-163903
> base:   v6.4-rc6
> patch link:    https://lore.kernel.org/r/20230613083626.227476-3-frank%40oltmanns.dev
> patch subject: [PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation
> config: csky-randconfig-r011-20230612 (https://download.01.org/0day-ci/archive/20230613/202306132038.nUB6hmCv-lkp@intel.com/config)
> compiler: csky-linux-gcc (GCC) 12.3.0
> reproduce (this is a W=1 build):
>         mkdir -p ~/bin
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         git checkout v6.4-rc6
>         b4 shazam https://lore.kernel.org/r/20230613083626.227476-3-frank@oltmanns.dev
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=csky olddefconfig
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=csky SHELL=/bin/bash
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202306132038.nUB6hmCv-lkp@intel.com/
>
> All errors (new ones prefixed by >>, old ones prefixed by <<):
>
>>> ERROR: modpost: "clk_fractional_divider_general_approximation" [drivers/clk/clk_test.ko] undefined!

The issue seems to be that clk_fractional_divider_general_approximation
is not exported as a symbol, while the config builds the clk_test as a
module:
CONFIG_CLK_KUNIT_TEST=m

If I'm not mistaken, this means that I can't test
clk_fractional_divider_general_approximation directly. Instead I'd have
to test it using clk_fractional_divider_ops.round_rate.

Can someone more knowlegdable than me please confirm if my understanding
is correct?

Thanks,
  Frank
Re: [PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation
Posted by Frank Oltmanns 2 years, 7 months ago
Hi Stephen,

On 2023-06-13 at 10:36:26 +0200, Frank Oltmanns <frank@oltmanns.dev> wrote:
> In light of the recent discovery that the fractional divisor
> approximation does not utilize the full available range for clocks that
> are flagged CLK_FRAC_DIVIDER_ZERO_BASED, implement tests for the edge
> cases of this clock type.
>
> Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
> Link: https://lore.kernel.org/lkml/20230529133433.56215-1-frank@oltmanns.dev
> ---
>  drivers/clk/clk_test.c | 69 +++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 68 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
> index f9a5c2964c65..b247ba841cbd 100644
> --- a/drivers/clk/clk_test.c
> +++ b/drivers/clk/clk_test.c
> @@ -8,6 +8,9 @@
>  /* Needed for clk_hw_get_clk() */
>  #include "clk.h"
>
> +/* Needed for clk_fractional_divider_general_approximation */
> +#include "clk-fractional-divider.h"
> +
>  #include <kunit/test.h>
>
>  #define DUMMY_CLOCK_INIT_RATE	(42 * 1000 * 1000)
> @@ -2394,6 +2397,69 @@ static struct kunit_suite clk_mux_notifier_test_suite = {
>  	.test_cases = clk_mux_notifier_test_cases,
>  };
>
> +
> +/*
> + * Test that clk_fractional_divider_general_approximation will work with the
> + * highest available numerator and denominator.
> + */
> +static void clk_fd_test_round_rate_max_mn(struct kunit *test)
> +{
> +	struct clk_fractional_divider *fd;
> +	struct clk_hw *hw;
> +	unsigned long rate, parent_rate, m, n;
> +
> +	fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
> +	KUNIT_ASSERT_NOT_NULL(test, fd);
> +
> +	fd->mwidth = 3;
> +	fd->nwidth = 3;
> +
> +	hw = &fd->hw;
> +
> +	rate = DUMMY_CLOCK_RATE_1;
> +
> +	// Highest denominator, no flags
> +	parent_rate = 10 * DUMMY_CLOCK_RATE_1;
> +	clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
> +	KUNIT_EXPECT_EQ(test, m, 1);
> +	KUNIT_EXPECT_EQ(test, n, 7);
> +
> +	// Highest numerator, no flags
> +	parent_rate = DUMMY_CLOCK_RATE_1 / 10;
> +	clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
> +	KUNIT_EXPECT_EQ(test, m, 7);
> +	KUNIT_EXPECT_EQ(test, n, 1);

The two calls above aim at proving that the change does not break
existing functionality.

> +
> +	// Highest denominator, zero based
> +	parent_rate = 10 * DUMMY_CLOCK_RATE_1;
> +	fd->flags = CLK_FRAC_DIVIDER_ZERO_BASED;
> +	clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
> +	KUNIT_EXPECT_EQ(test, m, 1);
> +	KUNIT_EXPECT_EQ(test, n, 8);
> +
> +	// Highest numerator, zero based
> +	parent_rate = DUMMY_CLOCK_RATE_1 / 10;
> +	clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
> +	KUNIT_EXPECT_EQ(test, m, 8);
> +	KUNIT_EXPECT_EQ(test, n, 1);
> +}
> +
> +static struct kunit_case clk_fd_test_cases[] = {
> +	KUNIT_CASE(clk_fd_test_round_rate_max_mn),
> +	{}
> +};
> +
> +/*
> + * Test suite for a fractional divider clock.
> + *
> + * These tests exercise the fractional divider API: clk_recalc_rate,
> + * clk_set_rate(), clk_round_rate().
> + */
> +static struct kunit_suite clk_fd_test_suite = {
> +	.name = "clk-fd-test",
> +	.test_cases = clk_fd_test_cases,
> +};

Unfortunately, the style of the tests does not really match with the
style of the existing tests, because those where all aimed at the
framework itself and not at specific functions.

Please let me know, if you require any changes.

Thanks,
  Frank

> +
>  kunit_test_suites(
>  	&clk_leaf_mux_set_rate_parent_test_suite,
>  	&clk_test_suite,
> @@ -2406,6 +2472,7 @@ kunit_test_suites(
>  	&clk_range_maximize_test_suite,
>  	&clk_range_minimize_test_suite,
>  	&clk_single_parent_mux_test_suite,
> -	&clk_uncached_test_suite
> +	&clk_uncached_test_suite,
> +	&clk_fd_test_suite
>  );
>  MODULE_LICENSE("GPL v2");