Lines Matching +full:non +full:- +full:empty
1 // SPDX-License-Identifier: GPL-2.0
15 #include "string-stream.h"
18 /* For testing resource-managed free. */
45 /* Resource-managed initialization. */ in string_stream_managed_init_test()
49 KUNIT_EXPECT_EQ(test, stream->length, 0); in string_stream_managed_init_test()
50 KUNIT_EXPECT_TRUE(test, list_empty(&stream->fragments)); in string_stream_managed_init_test()
51 KUNIT_EXPECT_TRUE(test, (stream->gfp == GFP_KERNEL)); in string_stream_managed_init_test()
52 KUNIT_EXPECT_FALSE(test, stream->append_newlines); in string_stream_managed_init_test()
65 KUNIT_EXPECT_EQ(test, stream->length, 0); in string_stream_unmanaged_init_test()
66 KUNIT_EXPECT_TRUE(test, list_empty(&stream->fragments)); in string_stream_unmanaged_init_test()
67 KUNIT_EXPECT_TRUE(test, (stream->gfp == GFP_KERNEL)); in string_stream_unmanaged_init_test()
68 KUNIT_EXPECT_FALSE(test, stream->append_newlines); in string_stream_unmanaged_init_test()
76 struct string_stream_test_priv *priv = fake_test->priv; in string_stream_destroy_stub()
79 if (stream == priv->expected_free_stream) { in string_stream_destroy_stub()
80 if (priv->stream_was_freed) in string_stream_destroy_stub()
81 priv->stream_free_again = true; in string_stream_destroy_stub()
83 priv->stream_was_freed = true; in string_stream_destroy_stub()
89 * Avoid calling deactivate_static_stub() or changing current->kunit_test in string_stream_destroy_stub()
99 struct string_stream_test_priv *priv = test->priv; in string_stream_managed_free_test()
101 priv->expected_free_stream = NULL; in string_stream_managed_free_test()
102 priv->stream_was_freed = false; in string_stream_managed_free_test()
103 priv->stream_free_again = false; in string_stream_managed_free_test()
109 priv->expected_free_stream = kunit_alloc_string_stream(test, GFP_KERNEL); in string_stream_managed_free_test()
110 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->expected_free_stream); in string_stream_managed_free_test()
113 kunit_free_string_stream(test, priv->expected_free_stream); in string_stream_managed_free_test()
115 KUNIT_EXPECT_TRUE(test, priv->stream_was_freed); in string_stream_managed_free_test()
116 KUNIT_EXPECT_FALSE(test, priv->stream_free_again); in string_stream_managed_free_test()
122 struct string_stream_test_priv *priv = test->priv; in string_stream_resource_free_test()
129 fake_test->priv = priv; in string_stream_resource_free_test()
135 priv->expected_free_stream = NULL; in string_stream_resource_free_test()
136 priv->stream_was_freed = false; in string_stream_resource_free_test()
137 priv->stream_free_again = false; in string_stream_resource_free_test()
143 priv->expected_free_stream = kunit_alloc_string_stream(fake_test, GFP_KERNEL); in string_stream_resource_free_test()
144 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->expected_free_stream); in string_stream_resource_free_test()
146 /* Set current->kunit_test to fake_test so the static stub will be called. */ in string_stream_resource_free_test()
147 current->kunit_test = fake_test; in string_stream_resource_free_test()
149 /* Cleanup test - the stub function should be called */ in string_stream_resource_free_test()
152 /* Set current->kunit_test back to current test. */ in string_stream_resource_free_test()
153 current->kunit_test = test; in string_stream_resource_free_test()
155 KUNIT_EXPECT_TRUE(test, priv->stream_was_freed); in string_stream_resource_free_test()
156 KUNIT_EXPECT_FALSE(test, priv->stream_free_again); in string_stream_resource_free_test()
180 /* Sanity-check that our test string isn't truncated */ in string_stream_line_add_test()
201 /* Convert to NULL-terminated string */ in string_stream_line_add_test()
220 " 0123456789!$%^&*()_-+={}[]:;@'~#<>,.?/|"; in string_stream_variable_length_line_test()
238 offset = prandom_u32_state(&rnd) % (sizeof(line) - 1); in string_stream_variable_length_line_test()
240 total_len += sizeof(line) - offset; in string_stream_variable_length_line_test()
258 /* Convert to NULL-terminated string */ in string_stream_variable_length_line_test()
261 offset = prandom_u32_state(&rnd) % (sizeof(line) - 1); in string_stream_variable_length_line_test()
293 /* Append content of empty stream to empty stream */ in string_stream_append_test()
303 /* Append content of empty stream to non-empty stream */ in string_stream_append_test()
312 /* Append content of non-empty stream to non-empty stream */ in string_stream_append_test()
329 /* Append content of non-empty stream to empty stream */ in string_stream_append_test()
339 /* Appending the content of one string stream to one with auto-newlining. */
348 KUNIT_EXPECT_TRUE(test, stream_1->append_newlines); in string_stream_append_auto_newline_test()
378 /* Adding an empty string should not create a fragment. */
387 /* Formatted empty string */ in string_stream_append_empty_string_test()
390 KUNIT_EXPECT_TRUE(test, list_empty(&stream->fragments)); in string_stream_append_empty_string_test()
392 /* Adding an empty string to a non-empty stream */ in string_stream_append_empty_string_test()
394 original_frag_count = list_count_nodes(&stream->fragments); in string_stream_append_empty_string_test()
397 KUNIT_EXPECT_EQ(test, list_count_nodes(&stream->fragments), original_frag_count); in string_stream_append_empty_string_test()
433 KUNIT_EXPECT_TRUE(test, stream->append_newlines); in string_stream_auto_newline_test()
467 memset(test_line, 'x', sizeof(test_line) - 1); in string_stream_performance_test()
468 test_line[sizeof(test_line) - 1] = '\0'; in string_stream_performance_test()
472 offset = i % (sizeof(test_line) - 1); in string_stream_performance_test()
485 list_for_each_entry(frag_container, &stream->fragments, node) { in string_stream_performance_test()
489 len = strlen(frag_container->fragment); in string_stream_performance_test()
492 actual_bytes_used += ksize(frag_container->fragment); in string_stream_performance_test()
508 return -ENOMEM; in string_stream_test_init()
510 test->priv = priv; in string_stream_test_init()
532 .name = "string-stream-test",