Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
244 changes: 175 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,114 +1,220 @@
# Time

# C++ & Rust Bazel Template Repository
Unified time service library and distributed time synchronization infrastructure for automotive ECU software.

This repository serves as a **template** for setting up **C++ and Rust projects** using **Bazel**.
It provides a **standardized project structure**, ensuring best practices for:
[![Documentation](https://img.shields.io/badge/docs-time-blue)](https://eclipse-score.github.io/time)

- **Build configuration** with Bazel.
- **Testing** (unit and integration tests).
- **Documentation** setup.
- **CI/CD workflows**.
- **Development environment** configuration.
## Overview

Portable and high-performance implementation of time services for the S-CORE project.

This repository contains source code for time clocks, time distribution infrastructure, and PTP synchronization. The Time module is implemented in C++ and provides working examples demonstrating usage patterns.

High-level functionality provided by the Time module:

- **Clock Domains**: Four time sources accessed through unified `Clock<Tag>` API
- **SystemTime**: Wall-clock time (Unix epoch) for timestamps and user-visible time displays
- **SteadyTime**: Monotonic time for duration measurements and timeouts
- **HighResSteadyTime**: High-precision monotonic time for precise timing applications
- **VehicleTime**: PTP-synchronized time for distributed automotive applications requiring initialization
- **Unified API**: Type-safe `Clock<Tag>::GetInstance().Now()` returns `ClockSnapshot<TimePoint, Status>` with atomic time + metadata reads

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, we need to mention it here.
it is the implementtion details, not the actual fucntionality

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

- **Event Subscription**: `Subscribe<EventType>()` / `Unsubscribe<EventType>()` for status changes and PTP protocol data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is being used currently in PTP based timebase. I havea feeling, the current formulation is missleading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand your point but updated the wording to "timebase"

- **Time Infrastructure**
- **TimeDaemon**: Plugin-based time distribution daemon with IPC message broker

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to mention here message broker?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

- **TimeSlave**: PTP protocol implementation with offset calculation and rate adjustment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not the PTP protocol implementaiton only.
Could you elaborate bit more?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added more detail

- **Test Utilities**: Mock backends and `ScopedClockOverride` for comprehensive testing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is applicable to the interfaces only, but iun the full list.

Suggerstion, to update the list in general

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to clock domain section


All clock domains support nanosecond precision and compile-time domain selection preventing cross-domain timing errors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is applicable to the clock domains, as it mentioned. but why it stays like it is applicable to the full list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed "all"


---

## 📋 Public API

### Clock Domains

#### SystemTime

| Target | Purpose |
|--------|---------|
| `//score/time/system_time` | Wall-clock time (Unix epoch) for timestamps |
| `//score/time/system_time:system_time_mock` | Mock backend for SystemTime testing |
| `//score/time/system_time:interface` | Header-only interface (no backend) |

#### SteadyTime

| Target | Purpose |
|--------|---------|
| `//score/time/steady_time` | Monotonic time for duration measurement |
| `//score/time/steady_time:steady_time_mock` | Mock backend for SteadyTime testing |
| `//score/time/steady_time:interface` | Header-only interface (no backend) |

#### HighResSteadyTime

| Target | Purpose |
|--------|---------|
| `//score/time/high_res_steady_time` | High-precision monotonic time |
| `//score/time/high_res_steady_time:high_res_steady_time_mock` | Mock backend for HighResSteadyTime testing |
| `//score/time/high_res_steady_time:interface` | Header-only interface (no backend) |

#### VehicleTime

| Target | Purpose |
|--------|---------|
| `//score/time/vehicle_time` | PTP-synchronized vehicle time |
| `//score/time/vehicle_time:vehicle_time_mock` | Mock backend for VehicleTime testing |
| `//score/time/vehicle_time:interface` | Header-only interface (no backend) |

### Time Infrastructure

| Target | Purpose |
|--------|---------|
| `//score/time_daemon:time_daemon` | TimeDaemon binary for time distribution |
| `//score/time_slave:time_slave` | TimeSlave binary for PTP synchronization |

### Test Utilities

| Target | Purpose |
|--------|---------|
| `//score/time/clock:clock_test_utils` | ScopedClockOverride and ClockTestFactory utilities |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the TimeDaemon and TimeSalve ones?
they are not really public, but they are visible in order to make the image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a section for executable artifects

---

## ⚙️ Using as Dependency

Add to your `MODULE.bazel`:

```python
bazel_dep(name = "score_time", version = "x.x.x")
```

Check available versions in the [S-CORE Bazel Registry](https://github.com/eclipse-score/bazel_registry/tree/main/modules/score_time).
Comment thread
PiotrKorkus marked this conversation as resolved.
Outdated

### Using Unreleased Versions

To depend on an unreleased version (for development or testing), use a git override in your `MODULE.bazel`:

```python
git_override(
module_name = "score_time",
commit = "abc123...",
remote = "https://github.com/eclipse-score/time.git",
)
```

Replace the `commit` value with the specific git hash you want to use.

---

## 📂 Project Structure

| File/Folder | Description |
| ----------------------------------- | ------------------------------------------------- |
| `README.md` | Short description & build instructions |
| `src/` | Source files for the module |
| `tests/` | Unit tests (UT) and integration tests (IT) |
| `examples/` | Example files used for guidance |
| `docs/` | Documentation (Doxygen for C++ / mdBook for Rust) |
| `.github/workflows/` | CI/CD pipelines |
| `.vscode/` | Recommended VS Code settings |
| `.bazelrc`, `MODULE.bazel`, `BUILD` | Bazel configuration & settings |
| `project_config.bzl` | Project-specific metadata for Bazel macros |
| `LICENSE.md` | Licensing information |
| `CONTRIBUTION.md` | Contribution guidelines |
## 📖 Documentation

- **[Time Feature Documentation](https://eclipse-score.github.io/score/main/features/time/index.html)**: High-level feature overview and S-CORE platform integration
- **[Time Module Documentation](https://eclipse-score.github.io/time)**: Detailed API documentation, architecture, and requirements

Generate module documentation locally:

```bash
bazel run //:docs
```

---

## 🚀 Getting Started

This section contains information on how to build and use the Time module.

### 1️⃣ Clone the Repository

```sh
git clone https://github.com/eclipse-score/YOUR_PROJECT.git
cd YOUR_PROJECT
```bash
git clone https://github.com/eclipse-score/time.git
cd time
```

### 2️⃣ Build the Examples of module
### 2️⃣ Prerequisites

> DISCLAIMER: Depending what module implements, it's possible that different
> configuration flags needs to be set on command line.
- **C++ Compiler**: gcc/clang with C++17 support
- **Build System**: Bazel 8+ (managed via Bazelisk)
- **Operating System**: Linux (Ubuntu 24.04+)
- **Dependencies**: S-CORE Baselibs, Google Test
- **For QNX targets**: QNX 8.0 SDP

To build all targets of the module the following command can be used:
### 3️⃣ Development Environment

```sh
bazel build //src/...
```
Follow the [S-CORE Development Environment Guide](https://eclipse-score.github.io/score/main/contribute/development/development_environment.html) for Linux host setup requirements.

This command will instruct Bazel to build all targets that are under Bazel
package `src/`. The ideal solution is to provide single target that builds
artifacts, for example:
### 4️⃣ Building the Project

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we can drop numbering. they are missing in some headings, and they will be ahrd to maintain

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


```sh
bazel build //src/<module_name>:release_artifacts
Build all components for **Linux x86_64** by running:

```bash
bazel build //...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose to

  • specify the config explicitely
  • add the explicit subfoleders: //score/... //examples/...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

```

where `:release_artifacts` is filegroup target that collects all release
artifacts of the module.
Run all tests:

> NOTE: This is just proposal, the final decision is on module maintainer how
> the module code needs to be built.
```bash
bazel test //...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here as well, suggest to specify the score and examples subfoldeers in oder to minimize the risk not to touch the filex, which should be not be run.
also add the config

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

```

### 3️⃣ Run Tests
#### Other Platforms

```sh
bazel test //tests/...
**Linux AArch64**:
```bash
bazel build --config=time-arm64-linux //...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and everywhere: add the sibfolders

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

bazel test --config=time-arm64-linux //...
```

---
**QNX x86_64**:
```bash
bazel build --config=time-x86_64-qnx //...
bazel test --config=time-x86_64-qnx //...
```

## 🛠 Tools & Linters
**QNX AArch64**:
```bash
bazel build --config=time-aarch64-qnx //...
bazel test --config=time-aarch64-qnx //...
```

#### Testing with Sanitizers

The template integrates **tools and linters** from **centralized repositories** to ensure consistency across projects.
To test with AddressSanitizer, UBSan, and LeakSanitizer enabled:

- **C++:** `clang-tidy`, `cppcheck`, `Google Test`
- **Rust:** `clippy`, `rustfmt`, `Rust Unit Tests`
- **CI/CD:** GitHub Actions for automated builds and tests
```bash
bazel test --config=time-x86_64-linux --config=asan_ubsan_lsan --build_tests_only //...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the asan_ubsan_lsan donfig alrady contains the time-x86_64-linux one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at .bazelrc, I think no, it just sets sanitizer flags, debug symbols and test filters

```

---

## 📖 Documentation
## 💡 Examples

- A **centralized docs structure** is planned.
Working examples demonstrating clock usage patterns, testing approaches, and integration techniques. See [examples/](examples/) for complete usage examples.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would believe, i nthe examples/ there is no documentation available. at lease in the root folder.
then either need to add docs there or add some usefull info and explanation here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added more detail


---

## ⚙️ `project_config.bzl`
## 📂 Repository Structure

This file defines project-specific metadata used by Bazel macros, such as `dash_license_checker`.
```
├── score/
│ ├── time/ # Clock domains (SystemTime, SteadyTime, etc.)
│ ├── time_daemon/ # Time distribution daemon
│ ├── time_slave/ # PTP synchronization implementation
│ └── ts_client/ # Time status utilities (internal)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not hte utility
it is the library to communicate with time slave

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

├── examples/ # Usage examples and patterns
├── docs/ # Module documentation
└── tools/ # Build and development utilities
```

### 📌 Purpose
---

It provides structured configuration that helps determine behavior such as:
## 🤝 Contributing

- Source language type (used to determine license check file format)
- Safety level or other compliance info (e.g. ASIL level)
See our [Contributing Guide](CONTRIBUTION.md) for contribution guidelines and development workflow.

### 📄 Example Content
---

```python
PROJECT_CONFIG = {
"asil_level": "QM", # or "ASIL-A", "ASIL-B", etc.
"source_code": ["cpp", "rust"] # Languages used in the module
}
```
## 🔗 Support

### 🔧 Use Case
### Community

When used with macros like `dash_license_checker`, it allows dynamic selection of file types
(e.g., `cargo`, `requirements`) based on the languages declared in `source_code`.
- **Issues**: Report bugs and request features via [GitHub Issues](https://github.com/eclipse-score/time/issues)
- **Discussions**: Join time [Slack Channel](https://sdvworkinggroup.slack.com/archives/C0ADTA4SKUH)
Loading