drivers/iio/test/iio-test-gts.c
Source file repositories/reference/linux-study-clean/drivers/iio/test/iio-test-gts.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/test/iio-test-gts.c- Extension
.c- Size
- 15112 bytes
- Lines
- 516
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/device.hkunit/test.hlinux/device.hlinux/iio/iio-gts-helper.hlinux/iio/types.h
Detected Declarations
function ARRAY_SIZEfunction test_iio_gts_find_gain_for_scale_using_timefunction test_iio_gts_find_new_gain_sel_by_old_gain_timefunction test_iio_find_closest_gain_lowfunction test_iio_gts_total_gain_to_scalefunction test_iio_gts_chk_timesfunction test_iio_gts_chk_scales_allfunction test_iio_gts_chk_scales_t200function test_iio_gts_avail_test
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/* Unit tests for IIO light sensor gain-time-scale helpers
*
* Copyright (c) 2023 Matti Vaittinen <mazziesaccount@gmail.com>
*/
#include <kunit/device.h>
#include <kunit/test.h>
#include <linux/device.h>
#include <linux/iio/iio-gts-helper.h>
#include <linux/iio/types.h>
/*
* 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 needs to be.
*/
#define TEST_TSEL_50 1
#define TEST_TSEL_X_MIN TEST_TSEL_50
#define TEST_TSEL_100 0
#define TEST_TSEL_200 2
#define TEST_TSEL_400 4
#define TEST_TSEL_X_MAX TEST_TSEL_400
#define TEST_GSEL_1 0x00
#define TEST_GSEL_X_MIN TEST_GSEL_1
#define TEST_GSEL_4 0x08
#define TEST_GSEL_16 0x0a
#define TEST_GSEL_32 0x0b
#define TEST_GSEL_64 0x0c
#define TEST_GSEL_256 0x18
#define TEST_GSEL_512 0x19
#define TEST_GSEL_1024 0x1a
#define TEST_GSEL_2048 0x1b
#define TEST_GSEL_4096 0x1c
#define TEST_GSEL_X_MAX TEST_GSEL_4096
#define TEST_SCALE_1X 64
#define TEST_SCALE_MIN_X TEST_SCALE_1X
#define TEST_SCALE_2X 32
#define TEST_SCALE_4X 16
#define TEST_SCALE_8X 8
#define TEST_SCALE_16X 4
#define TEST_SCALE_32X 2
#define TEST_SCALE_64X 1
#define TEST_SCALE_NANO_128X 500000000
#define TEST_SCALE_NANO_256X 250000000
#define TEST_SCALE_NANO_512X 125000000
#define TEST_SCALE_NANO_1024X 62500000
#define TEST_SCALE_NANO_2048X 31250000
#define TEST_SCALE_NANO_4096X 15625000
#define TEST_SCALE_NANO_4096X2 7812500
#define TEST_SCALE_NANO_4096X4 3906250
#define TEST_SCALE_NANO_4096X8 1953125
#define TEST_SCALE_NANO_MAX_X TEST_SCALE_NANO_4096X8
/*
* Can't have this allocated from stack because the kunit clean-up will
* happen only after the test function has already gone
*/
static struct iio_gts gts;
/* Keep the gain and time tables unsorted to test the sorting */
static const struct 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
};
static const struct iio_itime_sel_mul gts_test_itimes[] = {
GAIN_SCALE_ITIME_US(100 * 1000, TEST_TSEL_100, 2),
GAIN_SCALE_ITIME_US(400 * 1000, TEST_TSEL_400, 8),
Annotation
- Immediate include surface: `kunit/device.h`, `kunit/test.h`, `linux/device.h`, `linux/iio/iio-gts-helper.h`, `linux/iio/types.h`.
- Detected declarations: `function ARRAY_SIZE`, `function test_iio_gts_find_gain_for_scale_using_time`, `function test_iio_gts_find_new_gain_sel_by_old_gain_time`, `function test_iio_find_closest_gain_low`, `function test_iio_gts_total_gain_to_scale`, `function test_iio_gts_chk_times`, `function test_iio_gts_chk_scales_all`, `function test_iio_gts_chk_scales_t200`, `function test_iio_gts_avail_test`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.