static void prefix_output(int fd_in, int fd_out, size_t pending_len, time_t start) { char timestamp[8 + 3 + 1]; /* '[HH:MM:SS] ' + 1 */ char buf[1024]; char *p = NULL; time_t elapsed, now; size_t read_len, tlen; tlen = sizeof(timestamp); while (pending_len > 0) { read_len = read(fd_in, buf, min(sizeof(buf), pending_len)); pending_len -= read_len; for (p = buf; read_len > 0; ++p, --read_len) { if (newline) { newline = false; now = time(NULL); elapsed = now - start; calculate_duration((char *)×tamp, tlen, elapsed); write(fd_out, timestamp, tlen - 1); } if (*p == '\n' || *p == '\r') newline = true; write(fd_out, p, 1); } } }
virtual void run_test(test_runner* tr) { double set_up_duration = 0.0, tear_down_duration = 0.0, test_duration = 0.0; timeval before, after; try { gettimeofday(&before, NULL); static_cast<test_impl* >(this)->suite_set_up(); gettimeofday(&after, NULL); set_up_duration = calculate_duration(&before, &after); tr->add_set_up_time(set_up_duration); } catch(std::exception& e) { std::cout << "Exception during " << static_cast<test_impl* >(this)->__lt_name__ << " set up" << std::endl; std::cout << e.what() << std::endl; } catch(...) { std::cout << "Exception during " << static_cast<test_impl* >(this)->__lt_name__ << " set up" << std::endl; } try { gettimeofday(&before, NULL); (*static_cast<test_impl*>(this))(tr); } catch(assert_unattended& au) { ; } catch(std::exception& e) { std::cout << "Exception during " << static_cast<test_impl* >(this)->__lt_name__ << " run" << std::endl; std::cout << e.what() << std::endl; if(tr->last_checkpoint_line != -1) std::cout << "Last checkpoint in " << tr->last_checkpoint_file << ":" << tr->last_checkpoint_line << std::endl; } catch(...) { std::cout << "Exception during " << static_cast<test_impl* >(this)->__lt_name__ << " run" << std::endl; if(tr->last_checkpoint_line != -1) std::cout << "Last checkpoint in " << tr->last_checkpoint_file << ":" << tr->last_checkpoint_line << std::endl; } gettimeofday(&after, NULL); test_duration = calculate_duration(&before, &after); tr->add_good_time(test_duration); std::cout << "- Time spent during \"" << static_cast<test_impl* >(this)->__lt_name__ << "\": " << test_duration << std::endl; try { gettimeofday(&before, NULL); static_cast<test_impl* >(this)->suite_tear_down(); gettimeofday(&after, NULL); tear_down_duration = calculate_duration(&before, &after); tr->add_tear_down_time(tear_down_duration); } catch(std::exception& e) { std::cout << "Exception during " << static_cast<test_impl* >(this)->__lt_name__ << " tear down" << std::endl; std::cout << e.what() << std::endl; } catch(...) { std::cout << "Exception during " << static_cast<test_impl* >(this)->__lt_name__ << " tear down" << std::endl; } double total = set_up_duration + test_duration + tear_down_duration; tr->add_total_time(total); }