tamil-mani-p/generate-script icon
public
Published on 5/21/2025
generate test script

Prompts
generate-script
A sample prompt
Create a function `execute_test(context)` to carry out a **single instance of a validation test** based on the test type defined in `context['test_config']['type']`.   Use only the fixed/static test conditions provided in `context['test_config']` (e.g., `vin`, `iload`, etc.) — do **not** implement sweeping logic.
Store the measured result in `context['raw_result']`.
---
### 🧠 Key Instructions
- Read the test type from `context['test_config']['type']`. - Fetch static input conditions like:
  - Input voltage: `vin = context['test_config'].get('vin')`
  - Load current: `iload = context['test_config'].get('iload')`
- Use instrument handles stored in `context['instruments']`, which may include:
  - `"psu"`: Power Supply
  - `"eload"`: Electronic Load
  - `"dmm"`: Digital Multimeter

- General measurement steps (adjust depending on test type):
  1. Set PSU voltage and enable output
  2. Set electronic load current and enable input
  3. Wait/stabilize (e.g., `time.sleep(0.5)`)
  4. Use DMM or other instruments to measure relevant DUT output
  5. Save all measurements and inputs to `context['raw_result']`

- Store results in the format:
  ```python
  context['raw_result'] = {
    "vin": <float>,
    "iload": <float>,
    "measured_output": <float>,
    "timestamp": "<UTC ISO timestamp>"
  }
  ```
  Do not compare against spec limits or print results — that belongs in a later log_results() step.

### Example context['test_config'] ```python
  {
    "type": "load_regulation",
    "vin": 5.0,
    "iload": 0.1,
    "expected": {
      "min": 4.8,
      "typ": 5.0,
      "max": 5.2
    }
  }
```
### Example Structure ```python
  def execute_test(context: dict) -> dict:
      import time
      instruments = context["instruments"]
      test_config = context["test_config"]

      vin = test_config.get("vin")
      iload = test_config.get("iload")

      psu = instruments["psu"]
      eload = instruments["eload"]
      dmm = instruments["dmm"]

      psu.write(f"VOLT {vin}")
      psu.write("OUTP ON")

      eload.write(f"CURR {iload}")
      eload.write("INPUT ON")

      time.sleep(0.5)

      measured_output = float(dmm.query("MEAS:VOLT?"))

      context["raw_result"] = {
          "vin": vin,
          "iload": iload,
          "measured_output": measured_output,
          "timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
      }

      return context
```
### Constraints - Only handle a single point of measurement — no loops or parameter sweeps. - Make sure logic adapts based on test type, but avoids hardcoding values. - Modular structure should make it easy to add more test types later.