/* * Please, read the "rant" from the top of the lib/test_linear_ranges.c if * you see a line of helper code which is not being tested. * * Then, please look at the line which is not being tested. Is this line * somehow unusually complex? If answer is "no", then chances are that the * "development inertia" caused by adding a test exceeds the benefits. * * If yes, then adding a test is probably a good idea but please stop for a * moment and consider the effort of changing all the tests when code gets * refactored. Eventually it neeeds to be.
*/
/* * Can't have this allocated from stack because the kunit clean-up will * happen only after the test function has already gone
*/ staticstruct iio_gts gts;
/* Keep the gain and time tables unsorted to test the sorting */ staticconststruct iio_gain_sel_pair gts_test_gains[] = {
GAIN_SCALE_GAIN(1, TEST_GSEL_1),
GAIN_SCALE_GAIN(4, TEST_GSEL_4),
GAIN_SCALE_GAIN(16, TEST_GSEL_16),
GAIN_SCALE_GAIN(32, TEST_GSEL_32),
GAIN_SCALE_GAIN(64, TEST_GSEL_64),
GAIN_SCALE_GAIN(256, TEST_GSEL_256),
GAIN_SCALE_GAIN(512, TEST_GSEL_512),
GAIN_SCALE_GAIN(1024, TEST_GSEL_1024),
GAIN_SCALE_GAIN(4096, TEST_GSEL_4096),
GAIN_SCALE_GAIN(2048, TEST_GSEL_2048), #define HWGAIN_MAX 4096
};
dev = test_init_iio_gain_scale(test, >s); if (!dev) return;
ret = iio_gts_find_gain_sel_for_scale_using_time(>s, TEST_TSEL_100,
TEST_SCALE_8X, 0, &gain_sel); /* * Meas time 100 => gain by time 2x * TEST_SCALE_8X matches total gain 8x * => required HWGAIN 4x
*/
KUNIT_EXPECT_EQ(test, 0, ret);
KUNIT_EXPECT_EQ(test, TEST_GSEL_4, gain_sel);
ret = iio_gts_find_gain_sel_for_scale_using_time(>s, TEST_TSEL_200, 0,
TEST_SCALE_NANO_256X, &gain_sel); /* * Meas time 200 => gain by time 4x * TEST_SCALE_256X matches total gain 256x * => required HWGAIN 256/4 => 64x
*/
KUNIT_EXPECT_EQ(test, 0, ret);
KUNIT_EXPECT_EQ(test, TEST_GSEL_64, gain_sel);
/* Min time, Min gain */
ret = iio_gts_find_gain_sel_for_scale_using_time(>s, TEST_TSEL_X_MIN,
TEST_SCALE_MIN_X, 0, &gain_sel);
KUNIT_EXPECT_EQ(test, 0, ret);
KUNIT_EXPECT_EQ(test, TEST_GSEL_1, gain_sel);
/* Max time, Max gain */
ret = iio_gts_find_gain_sel_for_scale_using_time(>s, TEST_TSEL_X_MAX,
0, TEST_SCALE_NANO_MAX_X, &gain_sel);
KUNIT_EXPECT_EQ(test, 0, ret);
KUNIT_EXPECT_EQ(test, TEST_GSEL_4096, gain_sel);
ret = iio_gts_find_gain_sel_for_scale_using_time(>s, TEST_TSEL_100, 0,
TEST_SCALE_NANO_256X, &gain_sel); /* * Meas time 100 => gain by time 2x * TEST_SCALE_256X matches total gain 256x * => required HWGAIN 256/2 => 128x (not in gain-table - unsupported)
*/
KUNIT_EXPECT_NE(test, 0, ret);
ret = iio_gts_find_gain_sel_for_scale_using_time(>s, TEST_TSEL_200, 0,
TEST_SCALE_NANO_MAX_X, &gain_sel); /* We can't reach the max gain with integration time smaller than MAX */
KUNIT_EXPECT_NE(test, 0, ret);
ret = iio_gts_find_gain_sel_for_scale_using_time(>s, TEST_TSEL_50, 0,
TEST_SCALE_NANO_MAX_X, &gain_sel); /* We can't reach the max gain with integration time smaller than MAX */
KUNIT_EXPECT_NE(test, 0, ret);
}
ret = iio_gts_find_new_gain_sel_by_old_gain_time(>s, old_gain,
old_time_sel, new_time_sel, &new_gain);
KUNIT_EXPECT_EQ(test, 0, ret); /* * Doubling the integration time doubles the total gain - so old * (hw)gain must be divided by two to compensate. => 32 / 2 => 16
*/
KUNIT_EXPECT_EQ(test, 16, new_gain);
old_gain = 4;
old_time_sel = TEST_TSEL_50;
new_time_sel = TEST_TSEL_200;
ret = iio_gts_find_new_gain_sel_by_old_gain_time(>s, old_gain,
old_time_sel, new_time_sel, &new_gain);
KUNIT_EXPECT_EQ(test, 0, ret); /* * gain by time 1x => 4x - (hw)gain 4x => 1x
*/
KUNIT_EXPECT_EQ(test, 1, new_gain);
old_gain = 512;
old_time_sel = TEST_TSEL_400;
new_time_sel = TEST_TSEL_50;
ret = iio_gts_find_new_gain_sel_by_old_gain_time(>s, old_gain,
old_time_sel, new_time_sel, &new_gain);
KUNIT_EXPECT_EQ(test, 0, ret); /* * gain by time 8x => 1x - (hw)gain 512x => 4096x)
*/
KUNIT_EXPECT_EQ(test, 4096, new_gain);
for (i = 0; i < ARRAY_SIZE(expected); i++)
KUNIT_EXPECT_EQ(test, expected[i], vals[i]);
}
staticvoid test_iio_gts_chk_scales_all(struct kunit *test, struct iio_gts *gts, constint *vals, int len)
{ staticconstint gains[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
1024, 2048, 4096, 4096 * 2, 4096 * 4,
4096 * 8}; int expected[ARRAY_SIZE(gains) * 2]; int i, ret; int exp_len = ARRAY_SIZE(gains) * 2;
KUNIT_EXPECT_EQ(test, exp_len, len); if (len != exp_len) return;
for (i = 0; i < ARRAY_SIZE(gains); i++) {
ret = iio_gts_total_gain_to_scale(gts, gains[i],
&expected[2 * i],
&expected[2 * i + 1]);
KUNIT_EXPECT_EQ(test, 0, ret); if (ret) return;
}
for (i = 0; i < ARRAY_SIZE(expected); i++)
KUNIT_EXPECT_EQ(test, expected[i], vals[i]);
}
staticvoid test_iio_gts_chk_scales_t200(struct kunit *test, struct iio_gts *gts, constint *vals, int len)
{ /* The gain caused by time 200 is 4x */ staticconstint gains[] = {
1 * 4,
4 * 4,
16 * 4,
32 * 4,
64 * 4,
256 * 4,
512 * 4,
1024 * 4,
2048 * 4,
4096 * 4
}; int expected[ARRAY_SIZE(gains) * 2]; int i, ret;
for (i = 0; i < ARRAY_SIZE(gains); i++) {
ret = iio_gts_total_gain_to_scale(gts, gains[i],
&expected[2 * i],
&expected[2 * i + 1]);
KUNIT_EXPECT_EQ(test, 0, ret); if (ret) return;
}
for (i = 0; i < ARRAY_SIZE(expected); i++)
KUNIT_EXPECT_EQ(test, expected[i], vals[i]);
}
staticvoid test_iio_gts_avail_test(struct kunit *test)
{ struct device *dev; int ret; int type, len; constint *vals;
dev = test_init_iio_gain_scale(test, >s); if (!dev) return;
/* test table building for times and iio_gts_avail_times() */
ret = iio_gts_avail_times(>s, &vals, &type, &len);
KUNIT_EXPECT_EQ(test, IIO_AVAIL_LIST, ret); if (ret) return;
/* Test table building for all scales and iio_gts_all_avail_scales() */
ret = iio_gts_all_avail_scales(>s, &vals, &type, &len);
KUNIT_EXPECT_EQ(test, IIO_AVAIL_LIST, ret); if (ret) return;
/* * Test table building for scales/time and * iio_gts_avail_scales_for_time()
*/
ret = iio_gts_avail_scales_for_time(>s, 200000, &vals, &type, &len);
KUNIT_EXPECT_EQ(test, IIO_AVAIL_LIST, ret); if (ret) return;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.