Skip to content

Commit f5418d7

Browse files
committed
Apply comments & add more tests
1 parent 9c28e4d commit f5418d7

File tree

4 files changed

+89
-7
lines changed

4 files changed

+89
-7
lines changed
Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1+
# Helper utility to generate sycl/version.hpp file which contains various
2+
# identifiers which can be used to distinguish different builds between each
3+
# other:
4+
#
5+
# __LIBSYCL_TIMESTAMP - timestamp of the latest commit made into sycl/ directory
6+
# in YYYYMMDD format
7+
#
8+
# __SYCL_COMPILER_VERSION - date when configure step was launched in YYYYMMDD
9+
# format. Deprecated
10+
#
11+
# Note: it may not always be the case that CMake configuration step was re-run
12+
# when a new commits is added and therefore, execute_process won't be re-run and
13+
# the hash won't be updated. It is not considered to be a problem, because for
14+
# local incremental builds made during the library/headers development the date
15+
# doesn't matter much and we can guarantee it to be always correct when we do
16+
# nightly builds.
117

2-
# Grab the date of the latest commit
18+
# Grab the date of the latest commit in sycl folder
319
execute_process(
4-
COMMAND git log -1 --format=%as # date in YYYY-MM-DD mode
5-
WORKING_DIRECTORY ${SYCL_ROOT_SOURCE_DIR}
6-
OUTPUT_VARIABLE GIT_COMMIT_DATE_TEMP
20+
# date in YYYYMMDD mode, see strftime for reference
21+
COMMAND git log -1 --format=%ad --date=format:%Y%m%d -- ${SYCL_ROOT_SOURCE_DIR}
22+
OUTPUT_VARIABLE __LIBSYCL_TIMESTAMP
723
OUTPUT_STRIP_TRAILING_WHITESPACE
824
)
925

10-
string(REPLACE "-" "" __LIBSYCL_TIMESTAMP ${GIT_COMMIT_DATE_TEMP})
11-
1226
# Legacy thing for backwards compatibility. Use of the current date is not
1327
# reliable, because we can always make new build from older commits.
1428
string(TIMESTAMP __SYCL_COMPILER_VERSION "%Y%m%d")
15-
configure_file("${sycl_src_dir}/version.hpp.in" "${SYCL_INCLUDE_BUILD_DIR}/sycl/version.hpp")
29+
configure_file(
30+
"${sycl_src_dir}/version.hpp.in"
31+
"${SYCL_INCLUDE_BUILD_DIR}/sycl/version.hpp"
32+
)

sycl/test/libsycl-timestamp.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s
2+
// expected-no-diagnostics
3+
4+
#include <sycl/sycl.hpp>
5+
6+
#ifndef __LIBSYCL_TIMESTAMP
7+
#error "__LIBSYCL_TIMESTAMP is expected to be defined by sycl.hpp"
8+
Some weird code to cause compilation error
9+
#endif

sycl/unittests/misc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ add_sycl_unittest(MiscTests SHARED
44
CircularBuffer.cpp
55
OsUtils.cpp
66
PropertyUtils.cpp
7+
LibSYCLTimestamp.cpp
78
)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//==------------------------ LibSYCLTimestamp.cpp --------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <sycl/version.hpp>
10+
11+
#include <gtest/gtest.h>
12+
13+
#include <string>
14+
#include <cctype>
15+
16+
#define _STR(e) #e
17+
#define STR(e) _STR(e)
18+
19+
TEST(LibSYCLTimestamp, Format) {
20+
// __LIBSYCL_TIMESTAMP format is YYYYMMDD
21+
std::string Timestamp = STR(__LIBSYCL_TIMESTAMP);
22+
23+
ASSERT_EQ(Timestamp.size(), 8u);
24+
25+
for (char C : Timestamp) {
26+
ASSERT_TRUE(std::isdigit(C));
27+
}
28+
29+
constexpr size_t Y0 = 0;
30+
constexpr size_t Y1 = 1;
31+
constexpr size_t M0 = 4;
32+
constexpr size_t M1 = 5;
33+
constexpr size_t D0 = 6;
34+
constexpr size_t D1 = 7;
35+
36+
// Safe enough test for the next 900+ years
37+
ASSERT_EQ(Timestamp[Y0], '2');
38+
// Safe enough test for the next 70+ years
39+
ASSERT_EQ(Timestamp[Y1], '0');
40+
41+
ASSERT_TRUE(Timestamp[M0] == '0' || Timestamp[M1] == '1');
42+
if (Timestamp[M0] == '1')
43+
ASSERT_TRUE(Timestamp[M1] >= '0' && Timestamp[M1] <= '2');
44+
ASSERT_FALSE(Timestamp[M0] == '0' && Timestamp[M1] == '0');
45+
46+
ASSERT_TRUE(Timestamp[D0] >= '0' && Timestamp[D0] <= '3');
47+
if (Timestamp[D0] == '3')
48+
ASSERT_TRUE(Timestamp[D1] == '0' || Timestamp[D1] == '1');
49+
ASSERT_FALSE(Timestamp[D0] == '0' && Timestamp[D1] == '0');
50+
}
51+
52+
TEST(LibSYCLTimestasmp, BasicAcceptance) {
53+
// Date when this feature was introduced
54+
ASSERT_TRUE(__LIBSYCL_TIMESTAMP >= 20241128);
55+
}

0 commit comments

Comments
 (0)