Mix Assertion, Logging, Unit Testing and Fuzzing with ZeroErr
Mix Assertion, Logging, Unit Testing and Fuzzing with ZeroErr Build Safer Modern C++ Application Speaker: Xiaofan Sun Date: Sep 19, 2024Self-Introduction • Got my Ph.D. from UC, Riverside Pointer: std::unique_ptrClass from third-party library: llvm::Value*Logging the Data // LOG(INFO) << Data; // ASSERT(a > b, “A > B is not true”, a, b); std::ostream& oper std::unique_ptr ptr); std::ostream& operator<<(std::ostream& out, llvm::Value* data); ......Logging the Data • Namespace pollution • Hard to implement with template • No extensibility • No customization 0 码力 | 54 页 | 961.46 KB | 5 月前3Exceptionally Bad: The Story on the Misuse of Exceptions and How to Do Better
in handler and rethrow Logging reported deep in stack instead of at handler site 2. Repackage the Exception as a different type with additional information and rethrow Logging reported at handler site site This can often lead to thinking modes where the logging and the exception/error type are conflated Pattern : Logging/repackaging the exception in the handler with extra information and then rethrow rethrow for error handling elsewhere 42 Bloomberg Exceptional Logging43 Bloomberg Exceptional Logging enum class component_type { text, graphic, heading}; int apply(int key, component_type type) { try0 码力 | 85 页 | 2.32 MB | 5 月前3COMPOSABLE C++
to achieve prioritization. handled unhandled request A B C t f f f t tCASE STUDY: LOGGING CASE STUDY: LOGGING From "Easy to Use, Hard to Misuse: Declarative Style in C++" (CppCon 2018) From "Easy };CASE STUDY: LOGGING CASE STUDY: LOGGING Given the Given the push push function, we can write various function, we can write various log_sink log_sink classes: classes:CASE STUDY: LOGGING CASE STUDY: STUDY: LOGGING Given the Given the push push function, we can write various function, we can write various log_sink log_sink classes: classes: "ordinary" sinks that send entries to di�erent places (�le0 码力 | 124 页 | 8.28 MB | 5 月前3Things Happening in SG14
Pattern Matching • Tooling and Ease-of-Coding • Networking • Parallel and Concurrent Computing • Logging and I/O • Numeric Computing • Miscellaneous 69P2966 requests • Requests from P2966 can be grouped Pattern Matching • Tooling and Ease-of-Coding • Networking • Parallel and Concurrent Computing • Logging and I/O • Numeric Computing • Miscellaneous 70 Like most groupings, this is imperfect but will facilities 118Logging and I/O 119P2966 requests: logging and I/O • Better logging facilities • Some languages have optional attributes to know “who called you” which can be useful for logging • std::stacktrace0 码力 | 148 页 | 1009.97 KB | 5 月前3Tracy: A Profiler You Don't Want to Miss
- Bjarne Stroustrup CppCon 2023 Keynote (literally three days ago!)Tracing program execution logging function calls (+ args & return) system events state changes debug/warning/error messages mostly information overload; sampling overhead; constrained by sampling frequencyTracing program execution logging function calls (+ args & return) system events state changes debug/warning/error messages mostly malloc() et al. shader compilation sorting, searching, container manipulations, … file, network, logging, … interrupts, user input activity, spurious wake-ups, … 46 Instrument the “usual suspects ”0 码力 | 84 页 | 8.70 MB | 5 月前3Tracy: A Profiler You Don't Want to Miss
Bjarne Stroustrup CppCon 2023 Opening Keynote (literally three days ago!)Tracing program execution logging function calls (+ args & return) system events state changes debug/warning/error messages mostly information overload; sampling overhead; constrained by sampling frequencyTracing program execution logging function calls (+ args & return) system events state changes debug/warning/error messages mostly malloc() et al. shader compilation sorting, searching, container manipulations, … file, network, logging, … interrupts, user input activity, spurious wake-ups, … 46 Instrument the “usual suspects ”0 码力 | 85 页 | 6.51 MB | 5 月前3failing successfully
Warnings & Logging Forms of out of band communication Succeed but also warn Fail but also log Logging can be used in short term to compensate for lack of error reporting Short term because logging isn’t always always appropriate Warnings should have a bona fide channel Logging shouldn’t be coupled into components Emit events Separate component consumes events and writes to log 41 Summary Don’t… ...assume failure0 码力 | 44 页 | 625.44 KB | 5 月前3MACRO-FREE TESTING WITH C++20
ASSERTIONS ASSERTIONS SUITES SUITES TESTS TESTS SECTIONS SECTIONS BDD BDD MATCHERS MATCHERS LOGGING LOGGING ...... 2 / 14UT - UT - C++20 ( C++20 ( , , ) SINGLE SINGLE (2K LOC) WITH NO EXTERNAL ASSERTIONS ASSERTIONS SUITES SUITES TESTS TESTS SECTIONS SECTIONS BDD BDD MATCHERS MATCHERS LOGGING LOGGING ...... 2 / 14HELLO WORLD - HELLO WORLD - HTTPS://GODBOLT.ORG/Z/Y43MXZ HTTPS://GODBOLT.ORG/Z/Y43MXZ0 码力 | 53 页 | 1.98 MB | 5 月前3Conan 1.21 Documentation
Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 10.6 Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . in order to execute the package’s cmake. See also: • Reference/Tools/environment_append 10.6 Logging 10.6.1 How to log and debug a conan execution You can use the CONAN_TRACE_FILE environment variable "DOWNLOADED_RECIPE", "_id": "zlib/1.2.8@lasote/stable", "duration": 2. (continues on next page) 10.6. Logging 131 Conan Documentation, Release 1.21.3 (continued from previous page) ˓→40762996673584, "files":0 码力 | 621 页 | 4.92 MB | 1 年前3Conan 1.22 Documentation
Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 10.6 Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . in order to execute the package’s cmake. See also: • Reference/Tools/environment_append 10.6 Logging 10.6.1 How to log and debug a conan execution You can use the CONAN_TRACE_FILE environment variable "DOWNLOADED_RECIPE", "_id": "zlib/1.2.8@lasote/stable", "duration": 2. (continues on next page) 10.6. Logging 131 Conan Documentation, Release 1.22.3 (continued from previous page) ˓→40762996673584, "files":0 码力 | 629 页 | 4.98 MB | 1 年前3
共 107 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11