string-stream.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * C++ stream style string builder used in KUnit for building messages.
  4. *
  5. * Copyright (C) 2019, Google LLC.
  6. * Author: Brendan Higgins <[email protected]>
  7. */
  8. #ifndef _KUNIT_STRING_STREAM_H
  9. #define _KUNIT_STRING_STREAM_H
  10. #include <linux/spinlock.h>
  11. #include <linux/types.h>
  12. #include <linux/stdarg.h>
  13. struct string_stream_fragment {
  14. struct kunit *test;
  15. struct list_head node;
  16. char *fragment;
  17. };
  18. struct string_stream {
  19. size_t length;
  20. struct list_head fragments;
  21. /* length and fragments are protected by this lock */
  22. spinlock_t lock;
  23. struct kunit *test;
  24. gfp_t gfp;
  25. };
  26. struct kunit;
  27. struct string_stream *alloc_string_stream(struct kunit *test, gfp_t gfp);
  28. int __printf(2, 3) string_stream_add(struct string_stream *stream,
  29. const char *fmt, ...);
  30. int string_stream_vadd(struct string_stream *stream,
  31. const char *fmt,
  32. va_list args);
  33. char *string_stream_get_string(struct string_stream *stream);
  34. int string_stream_append(struct string_stream *stream,
  35. struct string_stream *other);
  36. bool string_stream_is_empty(struct string_stream *stream);
  37. void string_stream_clear(struct string_stream *stream);
  38. void string_stream_destroy(struct string_stream *stream);
  39. #endif /* _KUNIT_STRING_STREAM_H */