Lines Matching +full:always +full:- +full:running
1 .. SPDX-License-Identifier: GPL-2.0
21 to unit test code that was otherwise un-unit-testable.
27 --------------
33 the kernel; for example, it does not intend to be an end-to-end testing
37 ---------------------
48 -------------
57 .. code-block:: c
68 In the above example ``example_test_success`` always passes because it does
70 ``example_test_failure`` always fails because it calls ``KUNIT_FAIL``, which is
81 .. code-block:: c
90 behavior of a function called ``add``; the first parameter is always of type
98 violated; however, the test will continue running, potentially trying other
112 .. code-block:: c
122 KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
128 KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
148 .. code-block:: c
152 struct mock_test_context *ctx = test->priv;
153 struct mock *mock = ctx->mock;
154 int param0 = 5, param1 = -5;
159 ret = mock->do_expect(mock,
164 KUNIT_EXPECT_EQ(test, -4, *((int *) ret));
179 related tests most unit testing frameworks - including KUnit - provide the
187 .. code-block:: c
232 implementer, and architecture-specific functions which have definitions selected
236 -------
258 the pointer to itself because the pointer to the parent is always a fixed offset
262 .. code-block:: c
278 return self->length * self->width;
283 self->parent.area = rectangle_area;
284 self->length = length;
285 self->width = width;
307 .. code-block:: c
316 .. code-block:: c
329 .. code-block:: c
340 count = min(count, FAKE_EEPROM_CONTENTS_SIZE - offset);
341 memcpy(buffer, this->contents + offset, count);
350 count = min(count, FAKE_EEPROM_CONTENTS_SIZE - offset);
351 memcpy(this->contents + offset, buffer, count);
358 this->parent.read = fake_eeprom_read;
359 this->parent.write = fake_eeprom_write;
360 memset(this->contents, 0, FAKE_EEPROM_CONTENTS_SIZE);
365 .. code-block:: c
374 struct eeprom_buffer_test *ctx = test->priv;
375 struct eeprom_buffer *eeprom_buffer = ctx->eeprom_buffer;
376 struct fake_eeprom *fake_eeprom = ctx->fake_eeprom;
379 eeprom_buffer->flush_count = SIZE_MAX;
381 eeprom_buffer->write(eeprom_buffer, buffer, 1);
382 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[0], 0);
384 eeprom_buffer->write(eeprom_buffer, buffer, 1);
385 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[1], 0);
387 eeprom_buffer->flush(eeprom_buffer);
388 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[0], 0xff);
389 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[1], 0xff);
394 struct eeprom_buffer_test *ctx = test->priv;
395 struct eeprom_buffer *eeprom_buffer = ctx->eeprom_buffer;
396 struct fake_eeprom *fake_eeprom = ctx->fake_eeprom;
399 eeprom_buffer->flush_count = 2;
401 eeprom_buffer->write(eeprom_buffer, buffer, 1);
402 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[0], 0);
404 eeprom_buffer->write(eeprom_buffer, buffer, 1);
405 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[0], 0xff);
406 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[1], 0xff);
411 struct eeprom_buffer_test *ctx = test->priv;
412 struct eeprom_buffer *eeprom_buffer = ctx->eeprom_buffer;
413 struct fake_eeprom *fake_eeprom = ctx->fake_eeprom;
416 eeprom_buffer->flush_count = 2;
418 eeprom_buffer->write(eeprom_buffer, buffer, 1);
419 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[0], 0);
421 eeprom_buffer->write(eeprom_buffer, buffer, 2);
422 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[0], 0xff);
423 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[1], 0xff);
425 KUNIT_EXPECT_EQ(test, fake_eeprom->contents[2], 0);
435 ctx->fake_eeprom = kunit_kzalloc(test, sizeof(*ctx->fake_eeprom), GFP_KERNEL);
436 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->fake_eeprom);
437 fake_eeprom_init(ctx->fake_eeprom);
439 ctx->eeprom_buffer = new_eeprom_buffer(&ctx->fake_eeprom->parent);
440 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->eeprom_buffer);
442 test->priv = ctx;
449 struct eeprom_buffer_test *ctx = test->priv;
451 destroy_eeprom_buffer(ctx->eeprom_buffer);
454 .. _kunit-on-non-uml:
456 KUnit on non-UML architectures
462 are instances where being able to run architecture-specific code or test
463 against real hardware is desirable. For these reasons KUnit supports running on
466 Running existing KUnit tests on non-UML architectures
467 -----------------------------------------------------
469 There are some special considerations when running existing KUnit tests on
470 non-UML architectures:
472 * Hardware may not be deterministic, so a test that always passes or fails
473 when run under UML may not always do so on real hardware.
498 .. code-block:: none
506 .. code-block:: none
519 .. code-block:: bash
526 .. code-block:: bash
528 qemu-system-x86_64 -enable-kvm \
529 -m 1024 \
530 -kernel arch/x86_64/boot/bzImage \
531 -append 'console=ttyS0' \
532 --nographic
536 .. code-block:: none
542 ok 1 - example_simple_test
543 ok 1 - example
551 .. code-block:: none
558 .. code-block:: bash
560 modprobe example-test
570 -----------------------------------------
578 Even if you only ever plan on running your KUnit test on your hardware
585 Always prefer tests that run on UML to tests that only run under a particular
586 architecture, and always prefer tests that run under QEMU or another easy
592 in ``arch/some-arch/*``. Even so, try your best to write the test so that it
597 actual procedure for writing and running the tests is pretty much the same as
602 .. TODO(brendanhiggins@google.com): Add an actual example of an architecture-
608 in ``/sys/kernel/debug/kunit/<test-suite>``. The directory contains one file
610 - results: "cat results" displays results of each test case and the results