MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST

Function TEST

tensorflow/contrib/ffmpeg/default/ffmpeg_lib_utility_test.cc:33–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31namespace {
32
33TEST(FfmpegLibTest, TestTempDirectoryThreading) {
34 // Testing a fix for a bug that allowed different threads to create
35 // conflicting temp files.
36 // See github.com/tensorflow/tensorflow/issues/5804 for details.
37 const int32 kNumThreads = 10;
38 const int32 kNumWorkItems = 10000;
39 static constexpr size_t kStringsPerItem = 100;
40 Env* environment = Env::Default();
41 thread::ThreadPool pool(environment, "test", kNumThreads);
42
43 mutex mu;
44 std::vector<string> temp_filenames;
45 temp_filenames.reserve(kNumWorkItems * kStringsPerItem);
46
47 // Queue a large number of work items for the threads to process. Each work
48 // item creates a temp file and then deletes it.
49 for (int i = 0; i < kNumWorkItems; ++i) {
50 pool.Schedule([&mu, &temp_filenames, environment]() {
51 std::array<string, kStringsPerItem> buffer;
52 for (int32 j = 0; j < kStringsPerItem; ++j) {
53 buffer[j] = io::GetTempFilename("mp3");
54 TF_QCHECK_OK(environment->DeleteFile(buffer[j]));
55 }
56 mutex_lock l(mu);
57 for (const auto& fn : buffer) {
58 temp_filenames.push_back(fn);
59 }
60 });
61 }
62
63 // Wait until all work items are complete.
64 while (true) {
65 mutex_lock l(mu);
66 if (temp_filenames.size() == kNumWorkItems * kStringsPerItem) {
67 break;
68 }
69 }
70
71 // Check that no duplicates are created.
72 std::set<string> unique_filenames;
73 mutex_lock l(mu);
74 for (const auto& fn : temp_filenames) {
75 ASSERT_TRUE(unique_filenames.insert(fn).second);
76 }
77}
78
79} // namespace
80} // namespace ffmpeg

Callers

nothing calls this directly

Calls 8

DefaultFunction · 0.85
GetTempFilenameFunction · 0.85
reserveMethod · 0.45
ScheduleMethod · 0.45
DeleteFileMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected