Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion calnex/cert/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestBadVerify(t *testing.T) {
// CA signed by unknown authority
testTime, _ := time.Parse(time.RFC3339, "2025-02-03T12:00:00Z")
err = bundle.Verify("testhost.invalid", x509.VerifyOptions{CurrentTime: testTime})
require.ErrorAs(t, err, &x509.UnknownAuthorityError{})
require.Error(t, err)

// Invalid hostname
testTime, _ = time.Parse(time.RFC3339, "2025-02-03T12:00:00Z")
Expand Down
15 changes: 2 additions & 13 deletions cmd/ntpcheck/cmd/helper_64bit.go → cmd/ntpcheck/cmd/helper.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !386 && !darwin

/*
Copyright (c) Facebook, Inc. and its affiliates.

Expand All @@ -25,15 +23,6 @@ import (
)

func setSocketTimeout(connFd int, timeout time.Duration) error {
sec := int64(timeout / time.Second)
usec := timeout.Microseconds()
if timeout > time.Second {
usec = (timeout - time.Duration(sec)*time.Second).Microseconds()
}

timeoutVal := unix.Timeval{
Sec: sec,
Usec: usec,
}
return unix.SetsockoptTimeval(connFd, unix.SOL_SOCKET, unix.SO_RCVTIMEO, &timeoutVal)
tv := unix.NsecToTimeval(timeout.Nanoseconds())
return unix.SetsockoptTimeval(connFd, unix.SOL_SOCKET, unix.SO_RCVTIMEO, &tv)
}
39 changes: 0 additions & 39 deletions cmd/ntpcheck/cmd/helper_386.go

This file was deleted.

39 changes: 0 additions & 39 deletions cmd/ntpcheck/cmd/helper_darwin.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !darwin

/*
Copyright (c) Facebook, Inc. and its affiliates.

Expand All @@ -20,19 +18,15 @@ package cmd

import (
"fmt"
"syscall"
"time"
"unsafe"

"github.com/spf13/cobra"
"golang.org/x/sys/unix"
)

// cannot import sys/timex.h
const clockMonotonic = 4

func getRawMonotonic() float64 {
var ts syscall.Timespec
_, _, _ = syscall.Syscall(syscall.SYS_CLOCK_GETTIME, clockMonotonic, uintptr(unsafe.Pointer(&ts)), 0)
var ts unix.Timespec
_ = unix.ClockGettime(unix.CLOCK_MONOTONIC_RAW, &ts)
return float64(ts.Sec) + float64(ts.Nsec)/float64(1e9)
}

Expand Down Expand Up @@ -73,7 +67,6 @@ func track(interval time.Duration) {
var trackInterval time.Duration

func init() {
// track
utilsCmd.AddCommand(trackCmd)
trackCmd.Flags().DurationVarP(&trackInterval, "interval", "i", time.Second, "Measurement interval")
}
Expand Down
46 changes: 2 additions & 44 deletions cmd/ziffy/node/receiver_notlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,14 @@ package node

import (
"errors"
"net"
"time"

"github.com/facebook/time/ptp/protocol"
"github.com/google/gopacket"
)

type Receiver struct {
Config *Config
runningHandlers int64
Config *Config
}

type Sender struct {
Config *Config
inputQueue []chan *SwitchTrafficInfo
}

func (r *Receiver) incRunningHandlers() int64 {
r.runningHandlers++
return r.runningHandlers
}

func (r *Receiver) decRunningHandlers() int64 {
r.runningHandlers--
return r.runningHandlers
Config *Config
}

func (r *Receiver) Start() error {
Expand All @@ -62,28 +45,3 @@ func NewReceiver(...any) (*Receiver, error) {
func NewSender(...any) (*Sender, error) {
return nil, errors.New("sender unsupported on non-linux")
}

func (s *Sender) popAllQueue(_ []*PathInfo) {
s.inputQueue = nil
}

func (r *Receiver) handlePacket(_ gopacket.Packet) {
}

func parseSyncPacket(_ gopacket.Packet) (*protocol.SyncDelayReq, string, string, error) {
return nil, "", "", errors.New("unsupported on darwin")
}

func (s *Sender) clearPaths(routes []*PathInfo) []*PathInfo {
return routes
}

func sortSwitchesByHop(_ []SwitchTrafficInfo) {}

func formNewDest(_ *Config, _ int) net.IP {
return nil
}

func rackSwHostnameMonitor(_ string, _ time.Duration) (string, error) {
return "", errors.New("unsupported on darwin")
}
2 changes: 2 additions & 0 deletions cmd/ziffy/node/receiver_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux

/*
Copyright (c) Facebook, Inc. and its affiliates.

Expand Down
2 changes: 2 additions & 0 deletions cmd/ziffy/node/sender_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux

/*
Copyright (c) Facebook, Inc. and its affiliates.

Expand Down
12 changes: 12 additions & 0 deletions leapsectz/leapsectz.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ import (
// leapFile is a file containing leap second information
var leapFile = "/usr/share/zoneinfo/right/UTC"

// LeapFile returns the current default leap second file path
func LeapFile() string { return leapFile }

// SetLeapFile overrides the default leap second file path. Pass "" to reset.
func SetLeapFile(path string) {
if path == "" {
leapFile = "/usr/share/zoneinfo/right/UTC"
} else {
leapFile = path
}
}

var errBadData = errors.New("malformed time zone information")
var errUnsupportedVersion = errors.New("unsupported version")
var errNoLeapSeconds = errors.New("no leap seconds information found")
Expand Down
47 changes: 47 additions & 0 deletions ptp/c4u/utcoffset/utcoffset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,62 @@ limitations under the License.
package utcoffset

import (
"os"
"testing"
"time"

"github.com/facebook/time/leapsectz"
"github.com/stretchr/testify/require"
)

func TestRun(t *testing.T) {
if _, err := os.Stat(leapsectz.LeapFile()); err != nil {
ls := make([]leapsectz.LeapSecond, 0, len(leapTimestamps))
for i, ts := range leapTimestamps {
ls = append(ls, leapsectz.LeapSecond{Tleap: ts, Nleap: int32(i + 1)})
}
f, err := os.CreateTemp("", "leaptest-")
require.NoError(t, err)
defer os.Remove(f.Name())
err = leapsectz.Write(f, '2', ls, "UTC")
require.NoError(t, err)
require.NoError(t, f.Close())
leapsectz.SetLeapFile(f.Name())
defer leapsectz.SetLeapFile("")
}
u, err := Run()
require.NoError(t, err)
require.Greater(t, 50*time.Second, u)
require.Less(t, 30*time.Second, u)
}

// All 27 leap seconds (POSIX timestamps including prior leap seconds)
var leapTimestamps = []uint64{
78796800, // 1972-07-01
94694401, // 1973-01-01
126230402, // 1974-01-01
157766403, // 1975-01-01
189302404, // 1976-01-01
220924805, // 1977-01-01
252460806, // 1978-01-01
283996807, // 1979-01-01
315532808, // 1980-01-01
362793609, // 1981-07-01
394329610, // 1982-07-01
425865611, // 1983-07-01
489024012, // 1985-07-01
567993613, // 1988-01-01
631152014, // 1990-01-01
662688015, // 1991-01-01
709948816, // 1992-07-01
741484817, // 1993-07-01
773020818, // 1994-07-01
820454419, // 1996-01-01
867715220, // 1997-07-01
915148821, // 1999-01-01
1136073622, // 2006-01-01
1230768023, // 2009-01-01
1341100824, // 2012-07-01
1435708825, // 2015-07-01
1483228826, // 2017-01-01
}
2 changes: 1 addition & 1 deletion timestamp/timestamp_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestEnableTimestamps(t *testing.T) {

// HARDWARE
err = EnableTimestamps(HW, connFd, &net.Interface{Name: "lo", Index: 1})
require.Equal(t, fmt.Errorf("Unrecognized timestamp type: %s", HW), err)
require.Equal(t, fmt.Errorf("unrecognized timestamp type: %s", HW), err)
}

func TestReadPacketWithRXTimestamp(t *testing.T) {
Expand Down
Loading