|
6 | 6 | */
|
7 | 7 |
|
8 | 8 | #include <cstdio>
|
9 |
| -#include <cstdlib> |
10 | 9 | #include <random>
|
11 | 10 |
|
12 |
| -#include <unistd.h> |
13 |
| - |
14 | 11 | #include <gtest/gtest.h>
|
15 | 12 |
|
16 | 13 | #include <faiss/IVFlib.h>
|
17 | 14 | #include <faiss/IndexFlat.h>
|
18 | 15 | #include <faiss/IndexIVFFlat.h>
|
19 |
| -#include <faiss/IndexIVFPQ.h> |
20 | 16 | #include <faiss/IndexPreTransform.h>
|
21 | 17 | #include <faiss/MetaIndexes.h>
|
22 | 18 | #include <faiss/invlists/OnDiskInvertedLists.h>
|
23 | 19 |
|
24 |
| -namespace { |
25 |
| - |
26 |
| -struct Tempfilename { |
27 |
| - static pthread_mutex_t mutex; |
28 |
| - |
29 |
| - std::string filename = "/tmp/faiss_tmp_XXXXXX"; |
30 |
| - |
31 |
| - Tempfilename() { |
32 |
| - pthread_mutex_lock(&mutex); |
33 |
| - int fd = mkstemp(&filename[0]); |
34 |
| - close(fd); |
35 |
| - pthread_mutex_unlock(&mutex); |
36 |
| - } |
37 |
| - |
38 |
| - ~Tempfilename() { |
39 |
| - if (access(filename.c_str(), F_OK)) { |
40 |
| - unlink(filename.c_str()); |
41 |
| - } |
42 |
| - } |
| 20 | +#include "test_util.h" |
43 | 21 |
|
44 |
| - const char* c_str() { |
45 |
| - return filename.c_str(); |
46 |
| - } |
47 |
| -}; |
| 22 | +namespace { |
48 | 23 |
|
49 |
| -pthread_mutex_t Tempfilename::mutex = PTHREAD_MUTEX_INITIALIZER; |
| 24 | +pthread_mutex_t temp_file_mutex = PTHREAD_MUTEX_INITIALIZER; |
50 | 25 |
|
51 | 26 | typedef faiss::idx_t idx_t;
|
52 | 27 |
|
@@ -95,7 +70,7 @@ int compare_merged(
|
95 | 70 | std::vector<float> refD(k * nq);
|
96 | 71 |
|
97 | 72 | index_shards->search(nq, cd.queries.data(), k, refD.data(), refI.data());
|
98 |
| - Tempfilename filename; |
| 73 | + Tempfilename filename(&temp_file_mutex, "/tmp/faiss_tmp_XXXXXX"); |
99 | 74 |
|
100 | 75 | std::vector<idx_t> newI(k * nq);
|
101 | 76 | std::vector<float> newD(k * nq);
|
@@ -212,7 +187,7 @@ TEST(MERGE, merge_flat_vt) {
|
212 | 187 | TEST(MERGE, merge_flat_ondisk) {
|
213 | 188 | faiss::IndexShards index_shards(d, false, false);
|
214 | 189 | index_shards.own_indices = true;
|
215 |
| - Tempfilename filename; |
| 190 | + Tempfilename filename(&temp_file_mutex, "/tmp/faiss_tmp_XXXXXX"); |
216 | 191 |
|
217 | 192 | for (int i = 0; i < nindex; i++) {
|
218 | 193 | auto ivf = new faiss::IndexIVFFlat(&cd.quantizer, d, nlist);
|
|
0 commit comments