1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
use super::*;
use std::str::FromStr;

#[derive(Clone, PartialEq, Eq, Hash, Debug, Default, serde::Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct Options {
    pub allow: String,
    pub capture_directory: String,
    pub capture_on_error: StringBool,
    pub capture_packets: StringBool,
    pub capture_requests: StringBool,
    pub capture_responses: StringBool,
    pub capture_sockets: StringBool,
    pub cause: String,
    pub certificate_file: String,
    pub checkpoint: StringInt,
    pub child: StringBool,
    pub client_subtype: String,
    pub client_threads: StringInt,
    pub client_type: String,
    pub command_address: String,
    pub command_allow_no_pass: String,
    pub deny: String,
    pub command_deny_no_pass: String,
    pub command_enable: StringBool,
    pub command_port: StringInt,
    pub config_rotate: StringBool,
    pub config_rotate_dir: String,
    pub config_rotate_max: StringInt,
    pub connection_timeout: StringInt,
    pub core_priority: String,
    pub cpu_species: String,
    pub cpu_type: String,
    pub cpu_usage: StringInt,
    pub cpus: StringInt,
    pub crl_file: String,
    pub cuda_index: String,
    pub cycle_rate: StringInt,
    pub cycles: StringInt,
    pub daemon: StringBool,
    pub debug_sockets: StringBool,
    pub disable_sleep_when_active: StringBool,
    pub disable_viz: StringBool,
    pub dump_after_deadline: StringBool,
    pub exception_locations: StringBool,
    pub exit_when_done: StringBool,
    pub extra_core_args: String,
    pub fold_anon: String,
    pub gpu: String,
    pub gpu_index: String,
    pub gpu_usage: StringInt,
    pub gui_enabled: String,
    pub http_addresses: String,
    pub https_addresses: String,
    pub idle: StringBool,
    pub log: String,
    pub log_color: StringBool,
    pub log_crlf: StringBool,
    pub log_date: StringBool,
    pub log_date_periodically: StringInt,
    pub log_domain: StringBool,
    pub log_domain_levels: String,
    pub log_header: StringBool,
    pub log_level: StringBool,
    pub log_no_info_header: StringBool,
    pub log_redirect: StringBool,
    pub log_rotate: StringBool,
    pub log_rotate_dir: String,
    pub log_rotate_max: StringInt,
    pub log_short_level: StringBool,
    pub log_simple_domains: StringBool,
    pub log_thread_id: StringBool,
    pub log_thread_prefix: StringBool,
    pub log_time: StringBool,
    pub log_to_screen: StringBool,
    pub log_truncate: StringBool,
    pub machine_id: StringInt,
    pub max_connect_time: StringInt,
    pub max_connections: StringInt,
    pub max_packet_size: String,
    pub max_queue: StringInt,
    pub max_request_length: StringInt,
    pub max_shutdown_wait: StringInt,
    pub max_slot_errors: StringInt,
    pub max_unit_errors: StringInt,
    pub max_units: StringInt,
    pub memory: String,
    pub min_connect_time: StringInt,
    pub next_unit_percentage: StringInt,
    pub priority: String,
    pub no_assembly: StringBool,
    pub open_web_control: StringBool,
    pub opencl_index: String,
    pub os_species: String,
    pub os_type: String,
    pub passkey: String,
    pub password: String,
    pub pause_on_battery: StringBool,
    pub pause_on_start: StringBool,
    pub paused: StringBool,
    pub pid: StringBool,
    pub pid_file: String,
    pub power: Power,
    pub private_key_file: String,
    pub project_key: StringInt,
    pub proxy: String,
    pub proxy_enable: StringBool,
    pub proxy_pass: String,
    pub proxy_user: String,
    pub respawn: StringBool,
    pub service: StringBool,
    pub service_description: String,
    pub service_restart: StringBool,
    pub service_restart_delay: StringInt,
    pub session_cookie: String,
    pub session_lifetime: StringInt,
    pub session_timeout: StringInt,
    pub smp: StringBool,
    pub stack_traces: StringBool,
    pub stall_detection_enabled: StringBool,
    pub stall_percent: StringInt,
    pub stall_timeout: StringInt,
    pub team: StringInt,
    pub user: String,
    pub verbosity: StringInt,
    pub web_allow: String,
    pub web_deny: String,
    pub web_enable: StringBool,
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
pub struct StringBool(pub bool);

impl From<bool> for StringBool {
    fn from(b: bool) -> Self {
        Self(b)
    }
}

impl std::fmt::Display for StringBool {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl<'de> serde::de::Deserialize<'de> for StringBool {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        match serde_json::from_str(serde::de::Deserialize::deserialize(deserializer)?) {
            Ok(result) => Ok(Self(result)),
            Err(e) => Err(serde::de::Error::custom(e.to_string())),
        }
    }
}

impl core::str::FromStr for StringBool {
    type Err = Error;
    fn from_str(s: &str) -> Result<Self> {
        Ok(Self(str::parse(s)?))
    }
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
pub struct StringInt(pub i64);

impl From<i64> for StringInt {
    fn from(n: i64) -> Self {
        Self(n)
    }
}

impl std::fmt::Display for StringInt {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl<'de> serde::de::Deserialize<'de> for StringInt {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        match serde_json::from_str(serde::de::Deserialize::deserialize(deserializer)?) {
            Ok(n) => Ok(Self(n)),
            Err(e) => Err(serde::de::Error::custom(e.to_string())),
        }
    }
}

impl core::str::FromStr for StringInt {
    type Err = Error;
    fn from_str(s: &str) -> Result<Self> {
        Ok(Self(str::parse(s)?))
    }
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum Power {
    PowerNull,
    PowerLight,
    PowerMedium,
    PowerFull,
}

impl std::default::Default for Power {
    fn default() -> Self {
        Power::PowerNull
    }
}

impl core::str::FromStr for Power {
    type Err = Error;
    fn from_str(s: &str) -> Result<Self> {
        Ok(match s.to_uppercase().as_str() {
            "" => Power::PowerNull,
            "LIGHT" => Power::PowerLight,
            "MEDIUM" => Power::PowerMedium,
            "FULL" => Power::PowerFull,
            _ => return Err(Error::msg(format!("s is invalid: {}", s))),
        })
    }
}

impl std::fmt::Display for Power {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let s = match self {
            Power::PowerNull => "",
            Power::PowerLight => "LIGHT",
            Power::PowerMedium => "MEDIUM",
            Power::PowerFull => "FULL",
        };
        write!(f, "{}", s)
    }
}

impl<'de> serde::de::Deserialize<'de> for Power {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        match str::parse(serde::de::Deserialize::deserialize(deserializer)?) {
            Ok(p) => Ok(p),
            Err(e) => Err(serde::de::Error::custom(e.to_string())),
        }
    }
}

#[derive(Clone, PartialEq, Eq, Hash, Debug, Default, serde::Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct SlotQueueInfo {
    pub id: String,
    pub state: String,
    pub error: String,
    pub project: i64,
    pub run: i64,
    pub clone: i64,
    pub gen: i64,
    pub core: String,
    pub unit: String,
    pub percent_done: String,
    pub eta: FAHDuration,
    pub ppd: StringInt,
    pub credit_estimate: StringInt,
    pub waiting_on: String,
    pub next_attempt: FAHDuration,
    pub time_remaining: FAHDuration,
    pub total_frames: i64,
    pub frames_done: i64,
    pub assigned: FAHTime,
    pub timeout: FAHTime,
    pub deadline: FAHTime,
    pub ws: String,
    pub cs: String,
    pub attempts: i64,
    pub slot: String,
    pub tpf: FAHDuration,
    pub base_credit: StringInt,
}

/// None means invalid time.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
pub struct FAHTime(pub Option<chrono::DateTime<chrono::offset::Utc>>);

impl From<Option<chrono::DateTime<chrono::offset::Utc>>> for FAHTime {
    fn from(t: Option<chrono::DateTime<chrono::offset::Utc>>) -> Self {
        Self(t)
    }
}

impl From<chrono::DateTime<chrono::offset::Utc>> for FAHTime {
    fn from(t: chrono::DateTime<chrono::offset::Utc>) -> Self {
        Self(Some(t))
    }
}

const INVALID_TIME: &str = "<invalid>";

impl std::fmt::Display for FAHTime {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self.0 {
            Some(t) => write!(f, "{}", t),
            None => write!(f, "{}", INVALID_TIME),
        }
    }
}

impl<'de> serde::de::Deserialize<'de> for FAHTime {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = serde::de::Deserialize::deserialize(deserializer)?;
        if s == INVALID_TIME {
            return Ok(None.into());
        }

        match chrono::DateTime::parse_from_rfc3339(s) {
            Ok(t) => Ok(t.with_timezone(&chrono::offset::Utc).into()),
            Err(e) => Err(serde::de::Error::custom(e.to_string())),
        }
    }
}

/// None means unknown duration.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
pub struct FAHDuration(pub Option<chrono::Duration>);

impl From<Option<chrono::Duration>> for FAHDuration {
    fn from(d: Option<chrono::Duration>) -> Self {
        Self(d)
    }
}

impl From<chrono::Duration> for FAHDuration {
    fn from(d: chrono::Duration) -> Self {
        Self(Some(d))
    }
}

const UNKNOWN_TIME: &str = "unknowntime";

impl std::fmt::Display for FAHDuration {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self.0 {
            Some(d) => write!(f, "{}", d),
            None => write!(f, "{}", UNKNOWN_TIME),
        }
    }
}

impl<'de> serde::de::Deserialize<'de> for FAHDuration {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s: &str = serde::de::Deserialize::deserialize(deserializer)?;
        if s == UNKNOWN_TIME {
            return Ok(None.into());
        }

        // humantime cannot parse "x.x days"
        if let Some(number_of_days) = s.strip_suffix(" days") {
            if number_of_days.contains('.') {
                const MILLIS_PER_DAY: f64 = (1000 * 60 * 60 * 24) as f64;
                let n = f64::from_str(number_of_days)
                    .map_err(|e| serde::de::Error::custom(e.to_string()))?;
                return Ok(
                    chrono::Duration::milliseconds((MILLIS_PER_DAY * n).round() as i64).into(),
                );
            }
        }

        if let Some(number_of_seconds) = s.strip_suffix(" secs") {
            if number_of_seconds.contains('.') {
                const MILLIS_PER_SECOND: f64 = 1000.0;
                let n = f64::from_str(number_of_seconds)
                    .map_err(|e| serde::de::Error::custom(e.to_string()))?;
                return Ok(
                    chrono::Duration::milliseconds((MILLIS_PER_SECOND * n).round() as i64).into(),
                );
            }
        }

        let duration =
            humantime::parse_duration(s).map_err(|e| serde::de::Error::custom(e.to_string()))?;
        let result = chrono::Duration::from_std(duration)
            .map_err(|e| serde::de::Error::custom(e.to_string()))?;
        Ok(result.into())
    }
}

#[derive(Clone, PartialEq, Debug, Default, serde::Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct SimulationInfo {
    pub user: String,
    pub team: String,
    pub project: i64,
    pub run: i64,
    pub clone: i64,
    pub gen: i64,
    pub core_type: i64,
    pub core: String,
    pub total_iterations: i64,
    pub iterations_done: i64,
    pub energy: i64,
    pub temperature: i64,
    pub start_time: FAHTime,
    pub timeout: i64,
    pub deadline: i64,
    pub eta: i64,
    pub progress: f64,
    pub slot: i64,
}

#[derive(Clone, PartialEq, Eq, Debug, Default, serde::Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct SlotInfo {
    pub id: String,
    pub status: String,
    pub description: String,
    pub options: serde_json::map::Map<String, serde_json::Value>,
    pub reason: String,
    pub idle: bool,
}

#[derive(Clone, PartialEq, Eq, Debug, Default, serde::Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct SlotOptions {
    pub machine_id: String,
    pub paused: StringBool,
}

#[derive(Clone, PartialEq, Eq, Hash, Debug, Default, serde::Deserialize)]
pub struct Info {
    pub fah_client: FAHClient,
    pub cbang: CBang,
    pub system: System,
    pub libfah: LibFAH,
}

impl Info {
    pub fn new(src: Vec<Vec<serde_json::Value>>) -> Result<Self> {
        if src.len() < 4 {
            return Err(Error::msg(format!(
                "src should have 4 arrays but has {}",
                src.len()
            )));
        }

        let mut info = Info::default();

        for row in src {
            let mut row_iter = row.iter();
            let field: &mut dyn FieldSetter = match row_iter
                .next()
                .and_then(|e| e.as_str())
                .ok_or_else(|| Error::msg("unexpected type"))?
            {
                "FAHClient" => &mut info.fah_client,
                "CBang" => &mut info.cbang,
                "System" => &mut info.system,
                "libFAH" => &mut info.libfah,
                s => {
                    eprintln!("unexpected row type: {}", s);
                    continue;
                }
            };

            for v in row_iter {
                let entry = v.as_array().ok_or_else(|| Error::msg("unexpected type"))?;
                let k = entry
                    .get(0)
                    .and_then(|k| k.as_str())
                    .ok_or_else(|| Error::msg("unexpected type"))?;
                let v = entry
                    .get(1)
                    .and_then(|v| v.as_str())
                    .ok_or_else(|| Error::msg("unexpected type"))?;
                field.set(k, v)?;
            }
        }

        Ok(info)
    }
}

trait FieldSetter {
    fn set(&mut self, k: &str, value: &str) -> Result<()>;
}

#[derive(Clone, PartialEq, Eq, Hash, Debug, Default, serde::Deserialize)]
pub struct FAHClient {
    pub version: String,
    pub author: String,
    pub copyright: String,
    pub homepage: String,
    pub date: String,
    pub time: String,
    pub revision: String,
    pub branch: String,
    pub compiler: String,
    pub options: String,
    pub platform: String,
    pub bits: String,
    pub mode: String,
    pub args: String,
    pub config: String,
}

impl FieldSetter for FAHClient {
    fn set(&mut self, k: &str, value: &str) -> Result<()> {
        let v = value.to_string();
        match k {
            "Version" => self.version = v,
            "Author" => self.author = v,
            "Copyright" => self.copyright = v,
            "Homepage" => self.homepage = v,
            "Date" => self.date = v,
            "Time" => self.time = v,
            "Revision" => self.revision = v,
            "Branch" => self.branch = v,
            "Compiler" => self.compiler = v,
            "Options" => self.options = v,
            "Platform" => self.platform = v,
            "Bits" => self.bits = v,
            "Mode" => self.mode = v,
            "Args" => self.args = v,
            "Config" => self.config = v,
            _ => eprintln!("discarded unknown field: {}", k),
        };
        Ok(())
    }
}

#[derive(Clone, PartialEq, Eq, Hash, Debug, Default, serde::Deserialize)]
pub struct CBang {
    pub date: String,
    pub time: String,
    pub revision: String,
    pub branch: String,
    pub compiler: String,
    pub options: String,
    pub platform: String,
    pub bits: String,
    pub mode: String,
}

impl FieldSetter for CBang {
    fn set(&mut self, k: &str, value: &str) -> Result<()> {
        let v = value.to_string();
        match k {
            "Date" => self.date = v,
            "Time" => self.time = v,
            "Revision" => self.revision = v,
            "Branch" => self.branch = v,
            "Compiler" => self.compiler = v,
            "Options" => self.options = v,
            "Platform" => self.platform = v,
            "Bits" => self.bits = v,
            "Mode" => self.mode = v,
            _ => eprintln!("discarded unknown field: {}", k),
        };
        Ok(())
    }
}

#[derive(Clone, PartialEq, Eq, Hash, Debug, Default, serde::Deserialize)]
pub struct System {
    pub cpu: String,
    pub cpu_id: String,
    pub cpus: StringInt,
    pub memory: String,
    pub free_memory: String,
    pub threads: String,
    pub os_version: String,
    pub has_battery: String,
    pub on_battery: String,
    pub utc_offset: String,
    pub pid: String,
    pub cwd: String,
    pub os: String,
    pub os_arch: String,
    pub gpus: StringInt,
    // I don't have multiple GPUs so I can't test the "GPU 0" field
}

impl FieldSetter for System {
    fn set(&mut self, k: &str, value: &str) -> Result<()> {
        let v = value.to_string();
        match k {
            "CPU" => self.cpu = v,
            "CPU ID" => self.cpu_id = v,
            "CPUs" => self.cpus = str::parse(value)?,
            "Memory" => self.memory = v,
            "Free Memory" => self.free_memory = v,
            "Threads" => self.threads = v,
            "OS Version" => self.os_version = v,
            "Has Battery" => self.has_battery = v,
            "On Battery" => self.on_battery = v,
            "UTC Offset" => self.utc_offset = v,
            "PID" => self.pid = v,
            "CWD" => self.cwd = v,
            "OS" => self.os = v,
            "OS Arch" => self.os_arch = v,
            "GPUs" => self.gpus = str::parse(value)?,
            _ => {
                if !k.starts_with("GPU") && !k.starts_with("CUDA") && !k.starts_with("OpenCL") {
                    eprintln!("discarded unknown field: {}", k);
                }
            }
        };
        Ok(())
    }
}

#[derive(Clone, PartialEq, Eq, Hash, Debug, Default, serde::Deserialize)]
pub struct LibFAH {
    pub date: String,
    pub time: String,
    pub revision: String,
    pub branch: String,
    pub compiler: String,
    pub options: String,
    pub platform: String,
    pub bits: String,
    pub mode: String,
}

impl FieldSetter for LibFAH {
    fn set(&mut self, k: &str, value: &str) -> Result<()> {
        let v = value.to_string();
        match k {
            "Date" => self.date = v,
            "Time" => self.time = v,
            "Revision" => self.revision = v,
            "Branch" => self.branch = v,
            "Compiler" => self.compiler = v,
            "Options" => self.options = v,
            "Platform" => self.platform = v,
            "Bits" => self.bits = v,
            "Mode" => self.mode = v,
            _ => eprintln!("discarded unknown field: {}", k),
        };
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    #[allow(unused_imports)]
    use super::*;

    #[test]
    fn test_info_new() {
        let src = vec![
            vec![
                serde_json::Value::String("FAHClient".into()),
                serde_json::Value::Array(vec!["Version".into(), "7.6.13".into()]),
            ],
            vec![
                serde_json::Value::String("CBang".into()),
                serde_json::Value::Array(vec!["Date".into(), "Apr 20 2020".into()]),
            ],
            vec![
                serde_json::Value::String("System".into()),
                serde_json::Value::Array(vec![
                    "CPU ID".into(),
                    "Intel Management Engine is a backdoor".into(),
                ]),
                serde_json::Value::Array(vec!["CPUs".into(), "1".into()]),
            ],
            vec![
                serde_json::Value::String("libFAH".into()),
                serde_json::Value::Array(vec!["Date".into(), "Apr 20 2020".into()]),
            ],
        ];

        assert!(Info::new(Vec::new()).is_err());
        let result = Info::new(src).unwrap();
        assert!(!result.fah_client.version.is_empty());
        assert!(!result.system.cpu_id.is_empty());
        assert_eq!(result.system.cpus, StringInt(1));
    }

    #[test]
    fn test_fahduration_deserialize() {
        let s = r#""0.00 secs""#;
        let result: FAHDuration = serde_json::from_str(s).unwrap();
        assert_eq!(result.0.unwrap().num_seconds(), 0);

        let s = r#""1 days""#;
        let result: FAHDuration = serde_json::from_str(s).unwrap();
        assert_eq!(result.0.unwrap().num_days(), 1);

        let s = r#""1.1 days""#;
        let result: FAHDuration = serde_json::from_str(s).unwrap();
        assert_eq!(result.0.unwrap().num_days(), 1);
        assert_eq!(result.0.unwrap().num_milliseconds(), 95040000);
    }
}