Commit Graph

8 Commits

Author SHA1 Message Date
Nico Pache 2a517badae kunit: string-stream: Decouple string_stream from kunit
commit a3fdf784780ccb0008d630e8722d1389c49c7499
Author: Richard Fitzgerald <rf@opensource.cirrus.com>
Date:   Mon Aug 28 11:41:08 2023 +0100

    kunit: string-stream: Decouple string_stream from kunit

    Re-work string_stream so that it is not tied to a struct kunit. This is
    to allow using it for the log of struct kunit_suite.

    Instead of resource-managing individual allocations the whole string_stream
    can be resource-managed, if required.

        alloc_string_stream() now allocates a string stream that is
        not resource-managed.

        string_stream_destroy() now works on an unmanaged string_stream
        allocated by alloc_string_stream() and frees the entire
        string_stream (previously it only freed the fragments).

        string_stream_clear() has been made public for callers that
        want to free the fragments without destroying the string_stream.

    For resource-managed allocations use kunit_alloc_string_stream()
    and kunit_free_string_stream().

    In addition to this, string_stream_get_string() now returns an
    unmanaged buffer that the caller must kfree().

    Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
    Reviewed-by: David Gow <davidgow@google.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-39303
Signed-off-by: Nico Pache <npache@redhat.com>
2024-07-31 20:27:47 -06:00
Nico Pache d0c53e56b4 kunit: string-stream: Add kunit_alloc_string_stream()
commit 20631e154c78f4140fffe111f5c79464fae3c38c
Author: Richard Fitzgerald <rf@opensource.cirrus.com>
Date:   Mon Aug 28 11:41:07 2023 +0100

    kunit: string-stream: Add kunit_alloc_string_stream()

    Add function kunit_alloc_string_stream() to do a resource-managed
    allocation of a string stream, and corresponding
    kunit_free_string_stream() to free the resource-managed stream.

    This is preparing for decoupling the string_stream
    implementation from struct kunit, to reduce the amount of code
    churn when that happens. Currently:
     - kunit_alloc_string_stream() only calls alloc_string_stream().
     - kunit_free_string_stream() takes a struct kunit* which
       isn't used yet.

    Callers of the old alloc_string_stream() and
    string_stream_destroy() are all requesting a managed allocation
    so have been changed to use the new functions.

    alloc_string_stream() has been temporarily made static because
    its current behavior has been replaced with
    kunit_alloc_string_stream().

    Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
    Reviewed-by: David Gow <davidgow@google.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-39303
Signed-off-by: Nico Pache <npache@redhat.com>
2024-07-31 20:27:47 -06:00
Nico Pache 47a3d0786d kunit: string-stream: Add option to make all lines end with newline
commit a5abe7b201779b0000f1e8ab522e5c6fc0c413bf
Author: Richard Fitzgerald <rf@opensource.cirrus.com>
Date:   Mon Aug 28 11:41:04 2023 +0100

    kunit: string-stream: Add option to make all lines end with newline

    Add an optional feature to string_stream that will append a newline to
    any added string that does not already end with a newline. The purpose
    of this is so that string_stream can be used to collect log lines.

    This is enabled/disabled by calling string_stream_set_append_newlines().

    Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
    Reviewed-by: Rae Moar <rmoar@google.com>
    Reviewed-by: David Gow <davidgow@google.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-39303
Signed-off-by: Nico Pache <npache@redhat.com>
2024-07-31 20:27:47 -06:00
Nico Pache 7d8dd25512 kunit: drop test pointer in string_stream_fragment
commit 4db4598b5ed8fc26f5fd9312623a9ec5cebbe74a
Author: Daniel Latypov <dlatypov@google.com>
Date:   Fri Jul 22 17:15:31 2022 +0000

    kunit: drop test pointer in string_stream_fragment

    We already store the `struct kunit *test` in the string_stream object
    itself, so we need don't need to store a copy of this pointer in every
    fragment in the stream.

    Drop it, getting string_stream_fragment down the bare minimum: a
    list_head and the `char *` with the actual fragment.

    Signed-off-by: Daniel Latypov <dlatypov@google.com>
    Reviewed-by: David Gow <davidgow@google.com>
    Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-5618
Signed-off-by: Nico Pache <npache@redhat.com>
2023-11-02 15:26:54 -06:00
Nico Pache dba9a6413b kunit: string-stream: Simplify resource use
commit 78b1c6584fcedcf2d9687a4455c461859094cf04
Author: David Gow <davidgow@google.com>
Date:   Fri Jul 22 17:15:30 2022 +0000

    kunit: string-stream: Simplify resource use

    Currently, KUnit's string streams are themselves "KUnit resources".
    This is redundant since the stream itself is already allocated with
    kunit_kzalloc() and will thus be freed automatically at the end of the
    test.

    string-stream is only used internally within KUnit, and isn't using the
    extra features that resources provide like reference counting, being
    able to locate them dynamically as "test-local variables", etc.

    Indeed, the resource's refcount is never incremented when the
    pointer is returned. The fact that it's always manually destroyed is
    more evidence that the reference counting is unused.

    Signed-off-by: David Gow <davidgow@google.com>
    Signed-off-by: Daniel Latypov <dlatypov@google.com>
    Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-5618
Signed-off-by: Nico Pache <npache@redhat.com>
2023-11-02 15:26:53 -06:00
Karol Herbst 52935cce10 isystem: ship and use stdarg.h
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2072020
Upstream Status: v5.15-rc1

commit c0891ac15f0428ffa81b2e818d416bdf3cb74ab6
Author:     Alexey Dobriyan <adobriyan@gmail.com>
AuthorDate: Mon Aug  2 23:40:32 2021 +0300
Commit:     Masahiro Yamada <masahiroy@kernel.org>
CommitDate: Thu Aug 19 09:02:55 2021 +0900

    Ship minimal stdarg.h (1 type, 4 macros) as <linux/stdarg.h>.
    stdarg.h is the only userspace header commonly used in the kernel.

    GPL 2 version of <stdarg.h> can be extracted from
    http://archive.debian.org/debian/pool/main/g/gcc-4.2/gcc-4.2_4.2.4.orig.tar.gz

    Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
    Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Acked-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Signed-off-by: Karol Herbst <kherbst@redhat.com>
2022-04-19 15:52:25 +02:00
David Gow 44acdbb250 kunit: Add gnu_printf specifiers
Some KUnit functions use variable arguments to implement a printf-like
format string. Use the __printf() attribute to let the compiler warn if
invalid format strings are passed in.

If the kernel is build with W=1, it complained about the lack of these
specifiers, e.g.:
../lib/kunit/test.c:72:2: warning: function ‘kunit_log_append’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]

Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Daniel Latypov <dlatypov@google.com>
Acked-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-06-23 17:06:04 -06:00
Alan Maguire 109fb06fdc kunit: move string-stream.h to lib/kunit
string-stream interfaces are not intended for external use;
move them from include/kunit to lib/kunit accordingly.

Co-developed-by: Knut Omang <knut.omang@oracle.com>
Signed-off-by: Knut Omang <knut.omang@oracle.com>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Tested-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2020-01-09 16:41:05 -07:00